diff --git a/apps/xran/.gitignore b/apps/xran/.gitignore
new file mode 100644
index 0000000..e43b0f9
--- /dev/null
+++ b/apps/xran/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/apps/xran/BUCK b/apps/xran/BUCK
new file mode 100644
index 0000000..0c41439
--- /dev/null
+++ b/apps/xran/BUCK
@@ -0,0 +1,60 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:COMPILE',
+    '//lib:netty-handler',
+    '//lib:javax.ws.rs-api',
+    '//lib:org.apache.karaf.shell.console',
+    '//lib:netty-buffer',
+    '//utils/rest:onlab-rest',
+    '//core/store/serializers:onos-core-serializers',
+    '//cli:onos-cli',
+    '//lib:netty-transport',
+    '//core/common:onos-core-common',
+    ':netty-transport-sctp',
+    '//lib:swagger-annotations',
+    '//lib:JACKSON',
+    '//lib:NETTY'
+]
+
+BUNDLES = [
+    '//apps/xran:onos-apps-xran',
+]
+
+TEST_DEPS = [
+    '//lib:TEST',
+    '//lib:TEST_ADAPTERS',
+]
+
+EXCLUDED_BUNDLES = [
+    ':netty-transport-sctp',
+    '//lib:swagger-annotations'
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+    test_deps = TEST_DEPS,
+    web_context = '/onos/xran',
+    api_title = 'XRAN REST API',
+    api_package = 'org.onosproject.xran.impl.rest',
+    api_version = '1.0',
+    api_description = 'XRAN REST API',
+)
+
+onos_app (
+    app_name = 'org.onosproject.xran',
+    title = 'XRAN REST API',
+    category = 'Utilities',
+    url = 'http://onosproject.org',
+    description = 'XRAN REST API.',
+    included_bundles = BUNDLES,
+    excluded_bundles = EXCLUDED_BUNDLES,
+)
+
+remote_jar (
+    name = 'netty-transport-sctp',
+    out = 'netty-transport-sctp-4.1.13.Final.jar',
+    url = 'mvn:io.netty:netty-transport-sctp:jar:4.1.13.Final',
+    sha1 = '41e4ab1dc14cae445f93cef6421ce08f82804c1d',
+    maven_coords = 'io.netty:netty-transport-sctp:4.1.13.Final',
+    visibility = [ 'PUBLIC' ],
+)
diff --git a/apps/xran/apps_xran.iml b/apps/xran/apps_xran.iml
new file mode 100644
index 0000000..80f02c3
--- /dev/null
+++ b/apps/xran/apps_xran.iml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.git" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java/org.onosproject.xran" isTestSource="false"  packagePrefix="org.onosproject.xran"/>
+      <sourceFolder url="file://$MODULE_DIR$/src/main/webapp" isTestSource="false"  packagePrefix="apps.xran.src.main.webapp"/>
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java/org.onosproject.xran" isTestSource="true" />
+
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="cli" scope="COMPILE"  />
+    <orderEntry type="module" module-name="core_api" scope="COMPILE"  />
+    <orderEntry type="module" module-name="core_common" scope="COMPILE"  />
+    <orderEntry type="module" module-name="core_store_serializers" scope="COMPILE"  />
+    <orderEntry type="module" module-name="lib" scope="COMPILE"  />
+    <orderEntry type="module" module-name="utils_junit" scope="TEST"  />
+    <orderEntry type="module" module-name="utils_misc" scope="COMPILE"  />
+    <orderEntry type="module" module-name="utils_osgi" scope="COMPILE"  />
+    <orderEntry type="module" module-name="utils_rest" scope="COMPILE"  />
+    <orderEntry type="library" name="library_apps_xran_netty_transport_sctp" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_collections" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_configuration" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_io" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_lang" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_lang3" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_logging" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_commons_pool" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_easymock" scope="TEST" level="project"  />
+    <orderEntry type="library" name="library_lib_guava" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_guava_testlib" scope="TEST" level="project"  />
+    <orderEntry type="library" name="library_lib_hamcrest_all" scope="TEST" level="project"  />
+    <orderEntry type="library" name="library_lib_hamcrest_optional" scope="TEST" level="project"  />
+    <orderEntry type="library" name="library_lib_jackson_annotations" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_jackson_core" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_jackson_databind" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_javax_ws_rs_api" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_jsr305" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_junit" scope="TEST" level="project"  />
+    <orderEntry type="library" name="library_lib_netty_buffer" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_netty_common" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_netty_handler" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_netty_transport" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_felix_scr" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_felix_scr_annotations" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_karaf_features_core" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_karaf_shell_console" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_karaf_system_core" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_apache_servicemix_bundles_dom4j" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_org_osgi_compendium" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_osgi_core" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_slf4j_api" scope="COMPILE" level="project"  />
+    <orderEntry type="library" name="library_lib_swagger_annotations" scope="COMPILE" level="project"  />
+
+  </component>
+</module>
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranDeviceAgent.java b/apps/xran/src/main/java/org.onosproject.xran/XranDeviceAgent.java
new file mode 100644
index 0000000..812d6fc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranDeviceAgent.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import io.netty.channel.ChannelHandlerContext;
+
+/**
+ * Xran device agent interface.
+ */
+public interface XranDeviceAgent {
+
+    /**
+     * Add connected CELL.
+     *
+     * @param host IP of host trying to connect
+     * @param ctx  channel of CELL speaking to
+     * @return true if succeeded
+     */
+    boolean addConnectedCell(String host, ChannelHandlerContext ctx);
+
+    /**
+     * Remove disconnected CELL.
+     *
+     * @param host IP of host disconnected
+     * @return true if remove succeeded
+     */
+    boolean removeConnectedCell(String host);
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranDeviceListener.java b/apps/xran/src/main/java/org.onosproject.xran/XranDeviceListener.java
new file mode 100644
index 0000000..cfb4783
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranDeviceListener.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.xran.impl.entities.RnibCell;
+
+/**
+ * Xran Device Listener.
+ */
+public interface XranDeviceListener {
+
+    /**
+     * Add new CELL as a device.
+     *
+     * @param id CELL entity
+     */
+    void deviceAdded(RnibCell id);
+
+    /**
+     * Remove CELL.
+     *
+     * @param id CELL ECGI as device id
+     */
+    void deviceRemoved(DeviceId id);
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranHostAgent.java b/apps/xran/src/main/java/org.onosproject.xran/XranHostAgent.java
new file mode 100644
index 0000000..852ea6b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranHostAgent.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import io.netty.channel.ChannelHandlerContext;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibUe;
+
+/**
+ * Xran host agent interface.
+ */
+public interface XranHostAgent {
+
+    /**
+     * Add connected host.
+     *
+     * @param ue   UE entity
+     * @param cell CELL entity
+     * @param ctx  channel of CELL
+     * @return true if succeeded
+     */
+    boolean addConnectedHost(RnibUe ue, RnibCell cell, ChannelHandlerContext ctx);
+
+    /**
+     * Remove disconnected host.
+     *
+     * @param ue UE entity
+     * @return true if remove succeeded
+     */
+    boolean removeConnectedHost(RnibUe ue);
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranHostListener.java b/apps/xran/src/main/java/org.onosproject.xran/XranHostListener.java
new file mode 100644
index 0000000..b33b17c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranHostListener.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import org.onosproject.net.HostId;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.impl.entities.RnibUe;
+
+import java.util.Set;
+
+/**
+ * Xran Host Listener.
+ */
+public interface XranHostListener {
+
+    /**
+     * Add UE as a host with location the primary link.
+     *
+     * @param ue      UE entity
+     * @param ecgiSet All connected CELLs to this UE
+     */
+    void hostAdded(RnibUe ue, Set<ECGI> ecgiSet);
+
+    /**
+     * Remove UE based on Host Id.
+     *
+     * @param id Host Id generated from UE id
+     */
+    void hostRemoved(HostId id);
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranPacketProcessor.java b/apps/xran/src/main/java/org.onosproject.xran/XranPacketProcessor.java
new file mode 100644
index 0000000..e9f8cb0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranPacketProcessor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import io.netty.channel.ChannelHandlerContext;
+import org.onosproject.xran.asn1lib.pdu.XrancPdu;
+
+import java.io.IOException;
+
+/**
+ * Xran packet processor interface.
+ */
+public interface XranPacketProcessor {
+    /**
+     * Handle an incoming packet.
+     *
+     * @param pdu pdu of incoming packet
+     * @param ctx channel received the packet
+     * @throws IOException io exception
+     * @throws InterruptedException interrupted exception
+     */
+    void handlePacket(XrancPdu pdu, ChannelHandlerContext ctx) throws IOException, InterruptedException;
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranService.java b/apps/xran/src/main/java/org.onosproject.xran/XranService.java
new file mode 100644
index 0000000..c9b89fe
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranService.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import org.onosproject.xran.asn1lib.pdu.RRMConfig;
+import org.onosproject.xran.impl.entities.RnibLink;
+
+import java.util.Optional;
+import java.util.concurrent.SynchronousQueue;
+
+/**
+ * Created by dimitris on 7/27/17.
+ */
+public interface XranService {
+
+    /**
+     * Send a HandOff request from one link to another.
+     *
+     * @param newLink target LINK entity
+     * @param oldLink source LINK entity
+     * @return blocking queue for RESPONSE
+     * @throws InterruptedException interrupted exception
+     */
+    Optional<SynchronousQueue<String>> sendHoRequest(RnibLink newLink, RnibLink oldLink);
+
+    /**
+     * Add a device listener for CELL connections.
+     *
+     * @param listener listener
+     */
+    void addListener(XranDeviceListener listener);
+
+    /**
+     * Add a host listener for UE connections.
+     *
+     * @param listener listener
+     */
+    void addListener(XranHostListener listener);
+
+    /**
+     * Remove a CELL device listener.
+     *
+     * @param listener listener
+     */
+    void removeListener(XranDeviceListener listener);
+
+    /**
+     * Remove a UE host listener.
+     *
+     * @param listener listener
+     */
+    void removeListener(XranHostListener listener);
+
+    /**
+     * Send modified RRM configuration.
+     *
+     * @param rrmConfig configuration fields to send
+     * @return blocking queue for RESPONSE
+     */
+    Optional<SynchronousQueue<String>> sendModifiedRrm(RRMConfig rrmConfig);
+
+    /**
+     * Send scell add packet for specified LINK.
+     *
+     * @param link LINK entity
+     * @return blocking queue for RESPONSE
+     */
+    Optional<SynchronousQueue<String>> sendScellAdd(RnibLink link);
+
+    /**
+     * Send scell delete for specified LINK.
+     *
+     * @param link LINK entity
+     * @return true if sent correctly
+     */
+    boolean sendScellDelete(RnibLink link);
+
+    /**
+     * Get northbound timeout.
+     *
+     * @return interval in milliseconds
+     */
+    int getNorthboundTimeout();
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/XranStore.java b/apps/xran/src/main/java/org.onosproject.xran/XranStore.java
new file mode 100644
index 0000000..6c9c8fc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/XranStore.java
@@ -0,0 +1,396 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.BiMap;
+import io.netty.channel.ChannelHandlerContext;
+import org.onosproject.store.Store;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibLink;
+import org.onosproject.xran.impl.entities.RnibSlice;
+import org.onosproject.xran.impl.entities.RnibUe;
+import org.onosproject.xran.impl.identifiers.EcgiCrntiPair;
+import org.onosproject.xran.impl.identifiers.LinkId;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Created by dimitris on 7/22/17.
+ */
+public interface XranStore extends Store {
+
+    // LINKS STORE
+
+    /**
+     * Get all active links.
+     *
+     * @return list of links
+     */
+    List<RnibLink> getLinks();
+
+    /**
+     * Get all links for that CELL based on ECGI.
+     *
+     * @param ecgi CELL ECGI
+     *
+     * @return list of links
+     */
+    List<RnibLink> getLinks(ECGI ecgi);
+
+    /**
+     * Get all links for that CELL based on ECI.
+     *
+     * @param eciHex HEX string of ECI
+     *
+     * @return list of links
+     */
+    List<RnibLink> getLinks(String eciHex);
+
+    /**
+     * Get all links for the UE based on UE ID.
+     *
+     * @param ueId UE ID
+     *
+     * @return list of links
+     */
+    List<RnibLink> getLinks(long ueId);
+
+    /**
+     * Get a link between a CELL and UE.
+     *
+     * @param cellId HEX string ECI
+     * @param ueId   UE id
+     *
+     * @return link
+     */
+    Optional<RnibLink> getLink(String cellId, long ueId);
+
+    /**
+     * Get a link between a CELL's ECGI and UE's id.
+     *
+     * @param ecgi CELL ECGI
+     * @param ueId UE id
+     *
+     * @return link
+     */
+    Optional<RnibLink> getLink(ECGI ecgi, Long ueId);
+
+    /**
+     * Get link based on ECGI and CRNTI.
+     *
+     * @param src CELL ECGI
+     * @param dst CELL unique CRNTI
+     * @return link if found
+     */
+    Optional<RnibLink> getLink(ECGI src, CRNTI dst);
+
+    /**
+     * Modify specified link's RRM Configuration.
+     *
+     * @param link    LINK entity
+     * @param rrmConf json node of RRM Configuration
+     */
+    void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf);
+
+    /**
+     * Put new link to store.
+     *
+     * @param link LINK entity
+     */
+    void storeLink(RnibLink link);
+
+    /**
+     * Remove link from store.
+     *
+     * @param link LINK entity
+     *
+     * @return true if remove succeeded
+     */
+    boolean removeLink(LinkId link);
+
+    // NODES
+
+    /**
+     * Get all CELLs and UEs.
+     *
+     * @return list of UEs and CELLs
+     */
+    List<Object> getNodes();
+
+    /**
+     * Get all CELLs.
+     *
+     * @return list of CELLs
+     */
+    List<RnibCell> getCellNodes();
+
+    /**
+     * Get all UEs.
+     *
+     * @return list of UEs
+     */
+    List<RnibUe> getUeNodes();
+
+    /**
+     * Get node by node id.
+     *
+     * @param nodeId HEX string ECI or UE id
+     *
+     * @return CELL or UE
+     */
+    Optional<Object> getNode(String nodeId);
+
+    // CELL
+
+    /**
+     * Get cell based on HEX string ECI.
+     *
+     * @param eci HEX string ECI
+     *
+     * @return CELL if found
+     */
+    Optional<RnibCell> getCell(String eci);
+
+    /**
+     * Get cell based on ECGI.
+     *
+     * @param cellId CELL ECGI
+     *
+     * @return CELL if found
+     */
+    Optional<RnibCell> getCell(ECGI cellId);
+
+    /**
+     * Get cell based on PCI-ARFCN.
+     *
+     * @param id PCI-ARFCN
+     *
+     * @return CELL entity if found
+     */
+    Optional<RnibCell> getCell(PCIARFCN id);
+
+    /**
+     * Modify CELL's RRM Configuration.
+     *
+     * @param cell    CELL entity
+     * @param rrmConf json node of RRM Configuration
+     *
+     * @throws Exception exception
+     */
+    void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) throws Exception;
+
+    /**
+     * Put new CELL to the store.
+     *
+     * @param cell CELL entity
+     */
+    void storeCell(RnibCell cell);
+
+    /**
+     * Remove CELL from the store.
+     *
+     * @param ecgi CELL's ECGI
+     *
+     * @return ture if remove succeeded
+     */
+    boolean removeCell(ECGI ecgi);
+
+    /**
+     * Remove cell from three maps based on PCI-ARFCN.
+     *
+     * @param pciarfcn pci-arfcn of cell to remove
+     *
+     * @return true if remove succeeded
+     */
+    boolean removeCell(PCIARFCN pciarfcn);
+
+    // SLICE
+
+    /**
+     * Get SLICE based on SLICE id.
+     *
+     * @param sliceId SLICE id
+     * @return SLICE
+     */
+    Optional<RnibSlice> getSlice(long sliceId);
+
+    /**
+     * Put new SLICE to the store.
+     *
+     * @param attributes json node of SLICE attributes
+     *
+     * @return true if put succeeded
+     */
+    boolean createSlice(ObjectNode attributes);
+
+    /**
+     * Remove SLICE based on SLICE id.
+     *
+     * @param sliceId SLICE id
+     *
+     * @return true if remove succeeded
+     */
+    boolean removeCell(long sliceId);
+
+    // CONTROLLER
+
+    /**
+     * Get the xran xranServer instance.
+     *
+     * @return xran xranServer
+     */
+    Optional<XranService> getController();
+
+    /**
+     * Set the xran xranServer instance.
+     *
+     * @param controller xran xranServer
+     */
+    void setController(XranService controller);
+
+    // UE
+
+    /**
+     * Get UE based on UE id.
+     *
+     * @param euId UE id
+     *
+     * @return UE entity
+     */
+    Optional<RnibUe> getUe(long euId);
+
+    /**
+     * Get UE based on ECGI and CRNTI.
+     *
+     * @param ecgi  CELL ECGI
+     * @param crnti CELL unique CRNTI
+     *
+     * @return UE entity if found
+     */
+    Optional<RnibUe> getUe(ECGI ecgi, CRNTI crnti);
+
+    /**
+     * Put new UE to store.
+     *
+     * @param ue UE entity
+     */
+    void storeUe(RnibUe ue);
+
+    /**
+     * Put new UE to the store and update the ECGI, CRNTI pair.
+     *
+     * @param cell new primary CELL
+     * @param ue   UE
+     */
+    void storeUe(RnibCell cell, RnibUe ue);
+
+    /**
+     * Remove UE from store.
+     *
+     * @param ueId UE id
+     *
+     * @return true if remove succeeded
+     */
+    boolean removeUe(long ueId);
+
+    /**
+     * Put the PCI-ARFCN to ECGI map from new cell.
+     *
+     * @param value CELL entity
+     */
+    void storePciArfcn(RnibCell value);
+
+
+    /**
+     * Put inside ECGI to CTX map.
+     *
+     * @param value CELL entity to get ECGI from
+     * @param ctx   context channel
+     */
+    void storeCtx(RnibCell value, ChannelHandlerContext ctx);
+
+    /**
+     * Get context handler for specified ECGI.
+     *
+     * @param ecgi CELL ECGI
+     * @return context handler if found
+     */
+    Optional<ChannelHandlerContext> getCtx(ECGI ecgi);
+
+    /**
+     * Get the ECGI, CRNTI to UE bimap.
+     *
+     * @return BiMap of EcgiCrntiPair to Long
+     */
+    BiMap<EcgiCrntiPair, Long> getCrnti();
+
+    /**
+     * Put new ECGI, CRNTI pair of primary link to UE and remove old one.
+     *
+     * @param cell new primary CELL
+     * @param ue   UE
+     */
+    void storeCrnti(RnibCell cell, RnibUe ue);
+
+    /**
+     * Put a new primary link between a CELL and a UE.
+     *
+     * @param cell CELL entity
+     * @param ue   UE entity
+     */
+    void putPrimaryLink(RnibCell cell, RnibUe ue);
+
+    /**
+     * Put non-serving link based on CELL and CRNTI.
+     *
+     * @param cell  CELL entity
+     * @param crnti CRNTI
+     * @return new link after creation
+     */
+    Optional<RnibLink> putNonServingLink(RnibCell cell, CRNTI crnti);
+
+    /**
+     * Put non-serving link based on CELL and UE id.
+     *
+     * @param cell CELL entity
+     * @param ueId UE id
+     * @return new link after creation
+     */
+    Optional<RnibLink> putNonServingLink(RnibCell cell, Long ueId);
+
+    /**
+     * Get CRNTI based on UE id.
+     *
+     * @param ueId UE id
+     * @return UE if found
+     */
+    Optional<CRNTI> getCrnti(Long ueId);
+
+    /**
+     * Get primary CELL for specified UE.
+     *
+     * @param ue UE entity
+     * @return primary CELL if found
+     */
+    Optional<RnibCell> getPrimaryCell(RnibUe ue);
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A1Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A1Param.java
new file mode 100644
index 0000000..fbfbce8
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A1Param.java
@@ -0,0 +1,143 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A1Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ThresholdEUTRA a1Threshold = null;
+
+    public A1Param() {
+    }
+
+    public A1Param(byte[] code) {
+        this.code = code;
+    }
+
+    public ThresholdEUTRA getA1Threshold() {
+        return a1Threshold;
+    }
+
+    public void setA1Threshold(ThresholdEUTRA a1Threshold) {
+        this.a1Threshold = a1Threshold;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        sublength = a1Threshold.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            subCodeLength += length.decode(is);
+            a1Threshold = new ThresholdEUTRA();
+            subCodeLength += a1Threshold.decode(is, null);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a1Threshold != null) {
+            sb.append("a1Threshold: ");
+            a1Threshold.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("a1Threshold: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A2Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A2Param.java
new file mode 100644
index 0000000..4a269f7
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A2Param.java
@@ -0,0 +1,143 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A2Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ThresholdEUTRA a2Threshold = null;
+
+    public A2Param() {
+    }
+
+    public A2Param(byte[] code) {
+        this.code = code;
+    }
+
+    public ThresholdEUTRA getA2Threshold() {
+        return a2Threshold;
+    }
+
+    public void setA2Threshold(ThresholdEUTRA a2Threshold) {
+        this.a2Threshold = a2Threshold;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        sublength = a2Threshold.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            subCodeLength += length.decode(is);
+            a2Threshold = new ThresholdEUTRA();
+            subCodeLength += a2Threshold.decode(is, null);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a2Threshold != null) {
+            sb.append("a2Threshold: ");
+            a2Threshold.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("a2Threshold: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A3Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A3Param.java
new file mode 100644
index 0000000..4d1e9ea
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A3Param.java
@@ -0,0 +1,138 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A3Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerInteger a3Offset = null;
+
+    public A3Param() {
+    }
+
+    public A3Param(byte[] code) {
+        this.code = code;
+    }
+
+    public BerInteger getA3Offset() {
+        return a3Offset;
+    }
+
+    public void setA3Offset(BerInteger a3Offset) {
+        this.a3Offset = a3Offset;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += a3Offset.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            a3Offset = new BerInteger();
+            subCodeLength += a3Offset.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a3Offset != null) {
+            sb.append("a3Offset: ").append(a3Offset);
+        } else {
+            sb.append("a3Offset: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A4Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A4Param.java
new file mode 100644
index 0000000..fe514bc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A4Param.java
@@ -0,0 +1,143 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A4Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ThresholdEUTRA a4Threshold = null;
+
+    public A4Param() {
+    }
+
+    public A4Param(byte[] code) {
+        this.code = code;
+    }
+
+    public ThresholdEUTRA getA4Threshold() {
+        return a4Threshold;
+    }
+
+    public void setA4Threshold(ThresholdEUTRA a4Threshold) {
+        this.a4Threshold = a4Threshold;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        sublength = a4Threshold.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            subCodeLength += length.decode(is);
+            a4Threshold = new ThresholdEUTRA();
+            subCodeLength += a4Threshold.decode(is, null);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a4Threshold != null) {
+            sb.append("a4Threshold: ");
+            a4Threshold.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("a4Threshold: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A5Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A5Param.java
new file mode 100644
index 0000000..878ae61
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A5Param.java
@@ -0,0 +1,179 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A5Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ThresholdEUTRA a5Threshold1 = null;
+    private ThresholdEUTRA a5Threshold2 = null;
+
+    public A5Param() {
+    }
+
+    public A5Param(byte[] code) {
+        this.code = code;
+    }
+
+    public ThresholdEUTRA getA5Threshold1() {
+        return a5Threshold1;
+    }
+
+    public void setA5Threshold1(ThresholdEUTRA a5Threshold1) {
+        this.a5Threshold1 = a5Threshold1;
+    }
+
+    public ThresholdEUTRA getA5Threshold2() {
+        return a5Threshold2;
+    }
+
+    public void setA5Threshold2(ThresholdEUTRA a5Threshold2) {
+        this.a5Threshold2 = a5Threshold2;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        sublength = a5Threshold2.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        sublength = a5Threshold1.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            subCodeLength += length.decode(is);
+            a5Threshold1 = new ThresholdEUTRA();
+            subCodeLength += a5Threshold1.decode(is, null);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            subCodeLength += length.decode(is);
+            a5Threshold2 = new ThresholdEUTRA();
+            subCodeLength += a5Threshold2.decode(is, null);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a5Threshold1 != null) {
+            sb.append("a5Threshold1: ");
+            a5Threshold1.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("a5Threshold1: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a5Threshold2 != null) {
+            sb.append("a5Threshold2: ");
+            a5Threshold2.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("a5Threshold2: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A6Param.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A6Param.java
new file mode 100644
index 0000000..991a4bb
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/A6Param.java
@@ -0,0 +1,138 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class A6Param implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerInteger a6Offset = null;
+
+    public A6Param() {
+    }
+
+    public A6Param(byte[] code) {
+        this.code = code;
+    }
+
+    public BerInteger getA6Offset() {
+        return a6Offset;
+    }
+
+    public void setA6Offset(BerInteger a6Offset) {
+        this.a6Offset = a6Offset;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += a6Offset.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            a6Offset = new BerInteger();
+            subCodeLength += a6Offset.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (a6Offset != null) {
+            sb.append("a6Offset: ").append(a6Offset);
+        } else {
+            sb.append("a6Offset: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ARFCNValue.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ARFCNValue.java
new file mode 100644
index 0000000..1377785
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ARFCNValue.java
@@ -0,0 +1,43 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class ARFCNValue extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public ARFCNValue() {
+    }
+
+    public ARFCNValue(byte[] code) {
+        super(code);
+    }
+
+    public ARFCNValue(BigInteger value) {
+        super(value);
+    }
+
+    public ARFCNValue(long value) {
+        super(value);
+    }
+
+    @Override
+    public int hashCode() {
+        return value.intValue();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof ARFCNValue) {
+            return value.intValue() == ((ARFCNValue) obj).value.intValue();
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstCause.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstCause.java
new file mode 100644
index 0000000..cd30cfa
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstCause.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class AdmEstCause extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public AdmEstCause() {
+    }
+
+    public AdmEstCause(byte[] code) {
+        super(code);
+    }
+
+    public AdmEstCause(BigInteger value) {
+        super(value);
+    }
+
+    public AdmEstCause(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstResponse.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstResponse.java
new file mode 100644
index 0000000..57a1ce7
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstResponse.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class AdmEstResponse extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public AdmEstResponse() {
+    }
+
+    public AdmEstResponse(byte[] code) {
+        super(code);
+    }
+
+    public AdmEstResponse(BigInteger value) {
+        super(value);
+    }
+
+    public AdmEstResponse(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstStatus.java
new file mode 100644
index 0000000..1d5ac19
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/AdmEstStatus.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class AdmEstStatus extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public AdmEstStatus() {
+    }
+
+    public AdmEstStatus(byte[] code) {
+        super(code);
+    }
+
+    public AdmEstStatus(BigInteger value) {
+        super(value);
+    }
+
+    public AdmEstStatus(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/BitRate.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/BitRate.java
new file mode 100644
index 0000000..1eea849
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/BitRate.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class BitRate extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public BitRate() {
+    }
+
+    public BitRate(byte[] code) {
+        super(code);
+    }
+
+    public BitRate(BigInteger value) {
+        super(value);
+    }
+
+    public BitRate(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CACap.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CACap.java
new file mode 100644
index 0000000..32a4eda
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CACap.java
@@ -0,0 +1,236 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class CACap implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerInteger band = null;
+    private BerEnum caclassdl = null;
+    private BerEnum caclassul = null;
+    private BerBoolean crossCarrierSched = null;
+
+    public CACap() {
+    }
+
+    public CACap(byte[] code) {
+        this.code = code;
+    }
+
+    public BerInteger getBand() {
+        return band;
+    }
+
+    public void setBand(BerInteger band) {
+        this.band = band;
+    }
+
+    public BerEnum getCaclassdl() {
+        return caclassdl;
+    }
+
+    public void setCaclassdl(BerEnum caclassdl) {
+        this.caclassdl = caclassdl;
+    }
+
+    public BerEnum getCaclassul() {
+        return caclassul;
+    }
+
+    public void setCaclassul(BerEnum caclassul) {
+        this.caclassul = caclassul;
+    }
+
+    public BerBoolean getCrossCarrierSched() {
+        return crossCarrierSched;
+    }
+
+    public void setCrossCarrierSched(BerBoolean crossCarrierSched) {
+        this.crossCarrierSched = crossCarrierSched;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += crossCarrierSched.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += caclassul.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += caclassdl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += band.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            band = new BerInteger();
+            subCodeLength += band.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            caclassdl = new BerEnum();
+            subCodeLength += caclassdl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            caclassul = new BerEnum();
+            subCodeLength += caclassul.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            crossCarrierSched = new BerBoolean();
+            subCodeLength += crossCarrierSched.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (band != null) {
+            sb.append("band: ").append(band);
+        } else {
+            sb.append("band: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (caclassdl != null) {
+            sb.append("caclassdl: ").append(caclassdl);
+        } else {
+            sb.append("caclassdl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (caclassul != null) {
+            sb.append("caclassul: ").append(caclassul);
+        } else {
+            sb.append("caclassul: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crossCarrierSched != null) {
+            sb.append("crossCarrierSched: ").append(crossCarrierSched);
+        } else {
+            sb.append("crossCarrierSched: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CRNTI.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CRNTI.java
new file mode 100644
index 0000000..8b3245a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CRNTI.java
@@ -0,0 +1,45 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.Arrays;
+
+
+public class CRNTI extends BerBitString {
+
+    private static final long serialVersionUID = 1L;
+
+    public CRNTI() {
+    }
+
+    public CRNTI(byte[] code) {
+        super(code);
+    }
+
+    public CRNTI(byte[] value, int numBits) {
+        super(value, numBits);
+    }
+
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(value);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof CRNTI) {
+            return Arrays.equals(value, ((CRNTI) obj).value);
+        }
+        return super.equals(obj);
+    }
+
+    @Override
+    public String toString() {
+        return "" + DatatypeConverter.printHexBinary(value) + "";
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CandScell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CandScell.java
new file mode 100644
index 0000000..7ce4c2c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/CandScell.java
@@ -0,0 +1,169 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class CandScell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PhysCellId pci = null;
+    private ARFCNValue earfcnDl = null;
+
+    public CandScell() {
+    }
+
+    public CandScell(byte[] code) {
+        this.code = code;
+    }
+
+    public PhysCellId getPci() {
+        return pci;
+    }
+
+    public void setPci(PhysCellId pci) {
+        this.pci = pci;
+    }
+
+    public ARFCNValue getEarfcnDl() {
+        return earfcnDl;
+    }
+
+    public void setEarfcnDl(ARFCNValue earfcnDl) {
+        this.earfcnDl = earfcnDl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += earfcnDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += pci.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            pci = new PhysCellId();
+            subCodeLength += pci.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            earfcnDl = new ARFCNValue();
+            subCodeLength += earfcnDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pci != null) {
+            sb.append("pci: ").append(pci);
+        } else {
+            sb.append("pci: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (earfcnDl != null) {
+            sb.append("earfcnDl: ").append(earfcnDl);
+        } else {
+            sb.append("earfcnDl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DCCap.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DCCap.java
new file mode 100644
index 0000000..8b7e75a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DCCap.java
@@ -0,0 +1,138 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class DCCap implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerEnum drbTypeSplit = null;
+
+    public DCCap() {
+    }
+
+    public DCCap(byte[] code) {
+        this.code = code;
+    }
+
+    public BerEnum getDrbTypeSplit() {
+        return drbTypeSplit;
+    }
+
+    public void setDrbTypeSplit(BerEnum drbTypeSplit) {
+        this.drbTypeSplit = drbTypeSplit;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += drbTypeSplit.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            drbTypeSplit = new BerEnum();
+            subCodeLength += drbTypeSplit.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (drbTypeSplit != null) {
+            sb.append("drbTypeSplit: ").append(drbTypeSplit);
+        } else {
+            sb.append("drbTypeSplit: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DuplexMode.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DuplexMode.java
new file mode 100644
index 0000000..6e3b7f0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/DuplexMode.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class DuplexMode extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public DuplexMode() {
+    }
+
+    public DuplexMode(byte[] code) {
+        super(code);
+    }
+
+    public DuplexMode(BigInteger value) {
+        super(value);
+    }
+
+    public DuplexMode(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ECGI.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ECGI.java
new file mode 100644
index 0000000..e7c5cbd
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ECGI.java
@@ -0,0 +1,183 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class ECGI implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PLMNIdentity pLMNIdentity = null;
+    private EUTRANCellIdentifier eUTRANcellIdentifier = null;
+
+    public ECGI() {
+    }
+
+    public ECGI(byte[] code) {
+        this.code = code;
+    }
+
+    public PLMNIdentity getPLMNIdentity() {
+        return pLMNIdentity;
+    }
+
+    public void setPLMNIdentity(PLMNIdentity pLMNIdentity) {
+        this.pLMNIdentity = pLMNIdentity;
+    }
+
+    public EUTRANCellIdentifier getEUTRANcellIdentifier() {
+        return eUTRANcellIdentifier;
+    }
+
+    public void setEUTRANcellIdentifier(EUTRANCellIdentifier eUTRANcellIdentifier) {
+        this.eUTRANcellIdentifier = eUTRANcellIdentifier;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += eUTRANcellIdentifier.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += pLMNIdentity.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            pLMNIdentity = new PLMNIdentity();
+            subCodeLength += pLMNIdentity.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            eUTRANcellIdentifier = new EUTRANCellIdentifier();
+            subCodeLength += eUTRANcellIdentifier.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pLMNIdentity != null) {
+            sb.append("pLMNIdentity: ").append(pLMNIdentity);
+        } else {
+            sb.append("pLMNIdentity: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (eUTRANcellIdentifier != null) {
+            sb.append("eUTRANcellIdentifier: ").append(eUTRANcellIdentifier);
+        } else {
+            sb.append("eUTRANcellIdentifier: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ECGI ecgi = (ECGI) o;
+
+        return eUTRANcellIdentifier.equals(ecgi.eUTRANcellIdentifier);
+    }
+
+    @Override
+    public int hashCode() {
+        return eUTRANcellIdentifier.hashCode();
+    }
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ENBUES1APID.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ENBUES1APID.java
new file mode 100644
index 0000000..385e1c0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ENBUES1APID.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class ENBUES1APID extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public ENBUES1APID() {
+    }
+
+    public ENBUES1APID(byte[] code) {
+        super(code);
+    }
+
+    public ENBUES1APID(BigInteger value) {
+        super(value);
+    }
+
+    public ENBUES1APID(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDecision.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDecision.java
new file mode 100644
index 0000000..ab2a7f0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDecision.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class ERABDecision extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public ERABDecision() {
+    }
+
+    public ERABDecision(byte[] code) {
+        super(code);
+    }
+
+    public ERABDecision(BigInteger value) {
+        super(value);
+    }
+
+    public ERABDecision(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDirection.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDirection.java
new file mode 100644
index 0000000..57314e5
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABDirection.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class ERABDirection extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public ERABDirection() {
+    }
+
+    public ERABDirection(byte[] code) {
+        super(code);
+    }
+
+    public ERABDirection(BigInteger value) {
+        super(value);
+    }
+
+    public ERABDirection(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABID.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABID.java
new file mode 100644
index 0000000..b585441
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABID.java
@@ -0,0 +1,43 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class ERABID extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public ERABID() {
+    }
+
+    public ERABID(byte[] code) {
+        super(code);
+    }
+
+    public ERABID(BigInteger value) {
+        super(value);
+    }
+
+    public ERABID(long value) {
+        super(value);
+    }
+
+    @Override
+    public int hashCode() {
+        return value.intValue();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof ERABID) {
+            return value.intValue() == ((ERABID) obj).intValue();
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParams.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParams.java
new file mode 100644
index 0000000..c7f6e14
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParams.java
@@ -0,0 +1,146 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class ERABParams implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private List<ERABParamsItem> seqOf = null;
+
+    public ERABParams() {
+        seqOf = new ArrayList<ERABParamsItem>();
+    }
+
+    public ERABParams(byte[] code) {
+        this.code = code;
+    }
+
+    @JsonValue
+    public List<ERABParamsItem> getERABParamsItem() {
+        if (seqOf == null) {
+            seqOf = new ArrayList<ERABParamsItem>();
+        }
+        return seqOf;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        for (int i = (seqOf.size() - 1); i >= 0; i--) {
+            codeLength += seqOf.get(i).encode(os, true);
+        }
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+        int totalLength = length.val;
+
+        while (subCodeLength < totalLength) {
+            ERABParamsItem element = new ERABParamsItem();
+            subCodeLength += element.decode(is, true);
+            seqOf.add(element);
+        }
+        if (subCodeLength != totalLength) {
+            throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+        }
+        codeLength += subCodeLength;
+
+        return codeLength;
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (seqOf == null) {
+            sb.append("null");
+        } else {
+            Iterator<ERABParamsItem> it = seqOf.iterator();
+            if (it.hasNext()) {
+                it.next().appendAsString(sb, indentLevel + 1);
+                while (it.hasNext()) {
+                    sb.append(",\n");
+                    for (int i = 0; i < indentLevel + 1; i++) {
+                        sb.append("\t");
+                    }
+                    it.next().appendAsString(sb, indentLevel + 1);
+                }
+            }
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParamsItem.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParamsItem.java
new file mode 100644
index 0000000..09d646e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABParamsItem.java
@@ -0,0 +1,394 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class ERABParamsItem implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ERABID id = null;
+    private ERABDirection direction = null;
+    private ERABType type = null;
+    private QCI qci = null;
+    private BerInteger arp = null;
+    private BitRate gbrDl = null;
+    private BitRate gbrUl = null;
+    private BitRate mbrDl = null;
+    private BitRate mbrUl = null;
+
+    public ERABParamsItem() {
+    }
+
+    public ERABParamsItem(byte[] code) {
+        this.code = code;
+    }
+
+    public ERABID getId() {
+        return id;
+    }
+
+    public void setId(ERABID id) {
+        this.id = id;
+    }
+
+    public ERABDirection getDirection() {
+        return direction;
+    }
+
+    public void setDirection(ERABDirection direction) {
+        this.direction = direction;
+    }
+
+    public ERABType getType() {
+        return type;
+    }
+
+    public void setType(ERABType type) {
+        this.type = type;
+    }
+
+    public QCI getQci() {
+        return qci;
+    }
+
+    public void setQci(QCI qci) {
+        this.qci = qci;
+    }
+
+    public BerInteger getArp() {
+        return arp;
+    }
+
+    public void setArp(BerInteger arp) {
+        this.arp = arp;
+    }
+
+    public BitRate getGbrDl() {
+        return gbrDl;
+    }
+
+    public void setGbrDl(BitRate gbrDl) {
+        this.gbrDl = gbrDl;
+    }
+
+    public BitRate getGbrUl() {
+        return gbrUl;
+    }
+
+    public void setGbrUl(BitRate gbrUl) {
+        this.gbrUl = gbrUl;
+    }
+
+    public BitRate getMbrDl() {
+        return mbrDl;
+    }
+
+    public void setMbrDl(BitRate mbrDl) {
+        this.mbrDl = mbrDl;
+    }
+
+    public BitRate getMbrUl() {
+        return mbrUl;
+    }
+
+    public void setMbrUl(BitRate mbrUl) {
+        this.mbrUl = mbrUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += mbrUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 8
+        os.write(0x88);
+        codeLength += 1;
+
+        codeLength += mbrDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 7
+        os.write(0x87);
+        codeLength += 1;
+
+        codeLength += gbrUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 6
+        os.write(0x86);
+        codeLength += 1;
+
+        codeLength += gbrDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 5
+        os.write(0x85);
+        codeLength += 1;
+
+        codeLength += arp.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 4
+        os.write(0x84);
+        codeLength += 1;
+
+        codeLength += qci.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += type.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += direction.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += id.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            id = new ERABID();
+            subCodeLength += id.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            direction = new ERABDirection();
+            subCodeLength += direction.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            type = new ERABType();
+            subCodeLength += type.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            qci = new QCI();
+            subCodeLength += qci.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
+            arp = new BerInteger();
+            subCodeLength += arp.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
+            gbrDl = new BitRate();
+            subCodeLength += gbrDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
+            gbrUl = new BitRate();
+            subCodeLength += gbrUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
+            mbrDl = new BitRate();
+            subCodeLength += mbrDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
+            mbrUl = new BitRate();
+            subCodeLength += mbrUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (id != null) {
+            sb.append("id: ").append(id);
+        } else {
+            sb.append("id: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (direction != null) {
+            sb.append("direction: ").append(direction);
+        } else {
+            sb.append("direction: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (type != null) {
+            sb.append("type: ").append(type);
+        } else {
+            sb.append("type: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (qci != null) {
+            sb.append("qci: ").append(qci);
+        } else {
+            sb.append("qci: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (arp != null) {
+            sb.append("arp: ").append(arp);
+        } else {
+            sb.append("arp: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (gbrDl != null) {
+            sb.append("gbrDl: ").append(gbrDl);
+        } else {
+            sb.append("gbrDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (gbrUl != null) {
+            sb.append("gbrUl: ").append(gbrUl);
+        } else {
+            sb.append("gbrUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mbrDl != null) {
+            sb.append("mbrDl: ").append(mbrDl);
+        } else {
+            sb.append("mbrDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mbrUl != null) {
+            sb.append("mbrUl: ").append(mbrUl);
+        } else {
+            sb.append("mbrUl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponse.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponse.java
new file mode 100644
index 0000000..35b4fa6
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponse.java
@@ -0,0 +1,146 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class ERABResponse implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private List<ERABResponseItem> seqOf = null;
+
+    public ERABResponse() {
+        seqOf = new ArrayList<ERABResponseItem>();
+    }
+
+    public ERABResponse(byte[] code) {
+        this.code = code;
+    }
+
+    @JsonValue
+    public List<ERABResponseItem> getERABResponseItem() {
+        if (seqOf == null) {
+            seqOf = new ArrayList<ERABResponseItem>();
+        }
+        return seqOf;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        for (int i = (seqOf.size() - 1); i >= 0; i--) {
+            codeLength += seqOf.get(i).encode(os, true);
+        }
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+        int totalLength = length.val;
+
+        while (subCodeLength < totalLength) {
+            ERABResponseItem element = new ERABResponseItem();
+            subCodeLength += element.decode(is, true);
+            seqOf.add(element);
+        }
+        if (subCodeLength != totalLength) {
+            throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+        }
+        codeLength += subCodeLength;
+
+        return codeLength;
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (seqOf == null) {
+            sb.append("null");
+        } else {
+            Iterator<ERABResponseItem> it = seqOf.iterator();
+            if (it.hasNext()) {
+                it.next().appendAsString(sb, indentLevel + 1);
+                while (it.hasNext()) {
+                    sb.append(",\n");
+                    for (int i = 0; i < indentLevel + 1; i++) {
+                        sb.append("\t");
+                    }
+                    it.next().appendAsString(sb, indentLevel + 1);
+                }
+            }
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponseItem.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponseItem.java
new file mode 100644
index 0000000..4fc7e48
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABResponseItem.java
@@ -0,0 +1,169 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class ERABResponseItem implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ERABID id = null;
+    private ERABDecision decision = null;
+
+    public ERABResponseItem() {
+    }
+
+    public ERABResponseItem(byte[] code) {
+        this.code = code;
+    }
+
+    public ERABID getId() {
+        return id;
+    }
+
+    public void setId(ERABID id) {
+        this.id = id;
+    }
+
+    public ERABDecision getDecision() {
+        return decision;
+    }
+
+    public void setDecision(ERABDecision decision) {
+        this.decision = decision;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += decision.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += id.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            id = new ERABID();
+            subCodeLength += id.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            decision = new ERABDecision();
+            subCodeLength += decision.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (id != null) {
+            sb.append("id: ").append(id);
+        } else {
+            sb.append("id: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (decision != null) {
+            sb.append("decision: ").append(decision);
+        } else {
+            sb.append("decision: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABType.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABType.java
new file mode 100644
index 0000000..707eff5
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ERABType.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class ERABType extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public ERABType() {
+    }
+
+    public ERABType(byte[] code) {
+        super(code);
+    }
+
+    public ERABType(BigInteger value) {
+        super(value);
+    }
+
+    public ERABType(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/EUTRANCellIdentifier.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/EUTRANCellIdentifier.java
new file mode 100644
index 0000000..2f1394c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/EUTRANCellIdentifier.java
@@ -0,0 +1,39 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+
+import java.util.Arrays;
+
+
+public class EUTRANCellIdentifier extends BerBitString {
+
+    private static final long serialVersionUID = 1L;
+
+    public EUTRANCellIdentifier() {
+    }
+
+    public EUTRANCellIdentifier(byte[] code) {
+        super(code);
+    }
+
+    public EUTRANCellIdentifier(byte[] value, int numBits) {
+        super(value, numBits);
+    }
+
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(value);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof EUTRANCellIdentifier) {
+            return Arrays.equals(value, ((EUTRANCellIdentifier) obj).value);
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/HOFailureCause.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/HOFailureCause.java
new file mode 100644
index 0000000..f37f200
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/HOFailureCause.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class HOFailureCause extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public HOFailureCause() {
+    }
+
+    public HOFailureCause(byte[] code) {
+        super(code);
+    }
+
+    public HOFailureCause(BigInteger value) {
+        super(value);
+    }
+
+    public HOFailureCause(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/Hysteresis.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/Hysteresis.java
new file mode 100644
index 0000000..53c614c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/Hysteresis.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class Hysteresis extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public Hysteresis() {
+    }
+
+    public Hysteresis(byte[] code) {
+        super(code);
+    }
+
+    public Hysteresis(BigInteger value) {
+        super(value);
+    }
+
+    public Hysteresis(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2MeasReportInterval.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2MeasReportInterval.java
new file mode 100644
index 0000000..8d23563
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2MeasReportInterval.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class L2MeasReportInterval extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public L2MeasReportInterval() {
+    }
+
+    public L2MeasReportInterval(byte[] code) {
+        super(code);
+    }
+
+    public L2MeasReportInterval(BigInteger value) {
+        super(value);
+    }
+
+    public L2MeasReportInterval(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2ReportInterval.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2ReportInterval.java
new file mode 100644
index 0000000..e3febdb
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/L2ReportInterval.java
@@ -0,0 +1,265 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class L2ReportInterval implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private L2MeasReportInterval tRadioMeasReportPerUe = null;
+    private L2MeasReportInterval tRadioMeasReportPerCell = null;
+    private L2MeasReportInterval tRadioSchedReportPerUe = null;
+    private L2MeasReportInterval tRadioSchedReportPerCell = null;
+    private L2MeasReportInterval tPdcpMeasReportPerUe = null;
+
+    public L2ReportInterval() {
+    }
+
+    public L2ReportInterval(byte[] code) {
+        this.code = code;
+    }
+
+    public L2MeasReportInterval getTRadioMeasReportPerUe() {
+        return tRadioMeasReportPerUe;
+    }
+
+    public void setTRadioMeasReportPerUe(L2MeasReportInterval tRadioMeasReportPerUe) {
+        this.tRadioMeasReportPerUe = tRadioMeasReportPerUe;
+    }
+
+    public L2MeasReportInterval getTRadioMeasReportPerCell() {
+        return tRadioMeasReportPerCell;
+    }
+
+    public void setTRadioMeasReportPerCell(L2MeasReportInterval tRadioMeasReportPerCell) {
+        this.tRadioMeasReportPerCell = tRadioMeasReportPerCell;
+    }
+
+    public L2MeasReportInterval getTRadioSchedReportPerUe() {
+        return tRadioSchedReportPerUe;
+    }
+
+    public void setTRadioSchedReportPerUe(L2MeasReportInterval tRadioSchedReportPerUe) {
+        this.tRadioSchedReportPerUe = tRadioSchedReportPerUe;
+    }
+
+    public L2MeasReportInterval getTRadioSchedReportPerCell() {
+        return tRadioSchedReportPerCell;
+    }
+
+    public void setTRadioSchedReportPerCell(L2MeasReportInterval tRadioSchedReportPerCell) {
+        this.tRadioSchedReportPerCell = tRadioSchedReportPerCell;
+    }
+
+    public L2MeasReportInterval getTPdcpMeasReportPerUe() {
+        return tPdcpMeasReportPerUe;
+    }
+
+    public void setTPdcpMeasReportPerUe(L2MeasReportInterval tPdcpMeasReportPerUe) {
+        this.tPdcpMeasReportPerUe = tPdcpMeasReportPerUe;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += tPdcpMeasReportPerUe.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 4
+        os.write(0x84);
+        codeLength += 1;
+
+        codeLength += tRadioSchedReportPerCell.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += tRadioSchedReportPerUe.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += tRadioMeasReportPerCell.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += tRadioMeasReportPerUe.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            tRadioMeasReportPerUe = new L2MeasReportInterval();
+            subCodeLength += tRadioMeasReportPerUe.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            tRadioMeasReportPerCell = new L2MeasReportInterval();
+            subCodeLength += tRadioMeasReportPerCell.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            tRadioSchedReportPerUe = new L2MeasReportInterval();
+            subCodeLength += tRadioSchedReportPerUe.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            tRadioSchedReportPerCell = new L2MeasReportInterval();
+            subCodeLength += tRadioSchedReportPerCell.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
+            tPdcpMeasReportPerUe = new L2MeasReportInterval();
+            subCodeLength += tPdcpMeasReportPerUe.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (tRadioMeasReportPerUe != null) {
+            sb.append("tRadioMeasReportPerUe: ").append(tRadioMeasReportPerUe);
+        } else {
+            sb.append("tRadioMeasReportPerUe: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (tRadioMeasReportPerCell != null) {
+            sb.append("tRadioMeasReportPerCell: ").append(tRadioMeasReportPerCell);
+        } else {
+            sb.append("tRadioMeasReportPerCell: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (tRadioSchedReportPerUe != null) {
+            sb.append("tRadioSchedReportPerUe: ").append(tRadioSchedReportPerUe);
+        } else {
+            sb.append("tRadioSchedReportPerUe: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (tRadioSchedReportPerCell != null) {
+            sb.append("tRadioSchedReportPerCell: ").append(tRadioSchedReportPerCell);
+        } else {
+            sb.append("tRadioSchedReportPerCell: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (tPdcpMeasReportPerUe != null) {
+            sb.append("tPdcpMeasReportPerUe: ").append(tPdcpMeasReportPerUe);
+        } else {
+            sb.append("tPdcpMeasReportPerUe: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MMEUES1APID.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MMEUES1APID.java
new file mode 100644
index 0000000..d8876bc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MMEUES1APID.java
@@ -0,0 +1,44 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+import java.util.Objects;
+
+
+public class MMEUES1APID extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public MMEUES1APID() {
+    }
+
+    public MMEUES1APID(byte[] code) {
+        super(code);
+    }
+
+    public MMEUES1APID(BigInteger value) {
+        super(value);
+    }
+
+    public MMEUES1APID(long value) {
+        super(value);
+    }
+
+    @Override
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof MMEUES1APID) {
+            return Objects.equals(value, ((MMEUES1APID) obj).value);
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasID.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasID.java
new file mode 100644
index 0000000..e2f1be7
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasID.java
@@ -0,0 +1,615 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class MeasID implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerInteger measobjectId = null;
+    private BerInteger reportconfigId = null;
+    private Action action = null;
+    public MeasID() {
+    }
+
+    public MeasID(byte[] code) {
+        this.code = code;
+    }
+
+    public BerInteger getMeasobjectId() {
+        return measobjectId;
+    }
+
+    public void setMeasobjectId(BerInteger measobjectId) {
+        this.measobjectId = measobjectId;
+    }
+
+    public BerInteger getReportconfigId() {
+        return reportconfigId;
+    }
+
+    public void setReportconfigId(BerInteger reportconfigId) {
+        this.reportconfigId = reportconfigId;
+    }
+
+    public Action getAction() {
+        return action;
+    }
+
+    public void setAction(Action action) {
+        this.action = action;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        sublength = action.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += reportconfigId.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += measobjectId.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            measobjectId = new BerInteger();
+            subCodeLength += measobjectId.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            reportconfigId = new BerInteger();
+            subCodeLength += reportconfigId.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            subCodeLength += length.decode(is);
+            action = new Action();
+            subCodeLength += action.decode(is, null);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (measobjectId != null) {
+            sb.append("measobjectId: ").append(measobjectId);
+        } else {
+            sb.append("measobjectId: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportconfigId != null) {
+            sb.append("reportconfigId: ").append(reportconfigId);
+        } else {
+            sb.append("reportconfigId: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (action != null) {
+            sb.append("action: ");
+            action.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("action: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Action implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private Addmeasid addmeasid = null;
+        private Delmeasid delmeasid = null;
+        private BerBoolean hototarget = null;
+        public Action() {
+        }
+        public Action(byte[] code) {
+            this.code = code;
+        }
+
+        public Addmeasid getAddmeasid() {
+            return addmeasid;
+        }
+
+        public void setAddmeasid(Addmeasid addmeasid) {
+            this.addmeasid = addmeasid;
+        }
+
+        public Delmeasid getDelmeasid() {
+            return delmeasid;
+        }
+
+        public void setDelmeasid(Delmeasid delmeasid) {
+            this.delmeasid = delmeasid;
+        }
+
+        public BerBoolean getHototarget() {
+            return hototarget;
+        }
+
+        public void setHototarget(BerBoolean hototarget) {
+            this.hototarget = hototarget;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            if (hototarget != null) {
+                codeLength += hototarget.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+                os.write(0x82);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (delmeasid != null) {
+                codeLength += delmeasid.encode(os, false);
+                // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+                os.write(0xA1);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (addmeasid != null) {
+                codeLength += addmeasid.encode(os, false);
+                // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+                os.write(0xA0);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, null);
+        }
+
+        public int decode(InputStream is, BerTag berTag) throws IOException {
+
+            int codeLength = 0;
+            BerTag passedTag = berTag;
+
+            if (berTag == null) {
+                berTag = new BerTag();
+                codeLength += berTag.decode(is);
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+                addmeasid = new Addmeasid();
+                codeLength += addmeasid.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+                delmeasid = new Delmeasid();
+                codeLength += delmeasid.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+                hototarget = new BerBoolean();
+                codeLength += hototarget.decode(is, false);
+                return codeLength;
+            }
+
+            if (passedTag != null) {
+                return 0;
+            }
+
+            throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            if (addmeasid != null) {
+                sb.append("addmeasid: ");
+                addmeasid.appendAsString(sb, indentLevel + 1);
+                return;
+            }
+
+            if (delmeasid != null) {
+                sb.append("delmeasid: ");
+                delmeasid.appendAsString(sb, indentLevel + 1);
+                return;
+            }
+
+            if (hototarget != null) {
+                sb.append("hototarget: ").append(hototarget);
+                return;
+            }
+
+            sb.append("<none>");
+        }
+
+        public static class Addmeasid implements Serializable {
+
+            public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+            private static final long serialVersionUID = 1L;
+            @JsonIgnore
+            public byte[] code = null;
+            private List<BerInteger> seqOf = null;
+
+            public Addmeasid() {
+                seqOf = new ArrayList<BerInteger>();
+            }
+
+            public Addmeasid(byte[] code) {
+                this.code = code;
+            }
+
+            @JsonValue
+            public List<BerInteger> getBerInteger() {
+                if (seqOf == null) {
+                    seqOf = new ArrayList<BerInteger>();
+                }
+                return seqOf;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+                return encode(os, true);
+            }
+
+            public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    if (withTag) {
+                        return tag.encode(os) + code.length;
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                    codeLength += seqOf.get(i).encode(os, true);
+                }
+
+                codeLength += BerLength.encodeLength(os, codeLength);
+
+                if (withTag) {
+                    codeLength += tag.encode(os);
+                }
+
+                return codeLength;
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, true);
+            }
+
+            public int decode(InputStream is, boolean withTag) throws IOException {
+                int codeLength = 0;
+                int subCodeLength = 0;
+                if (withTag) {
+                    codeLength += tag.decodeAndCheck(is);
+                }
+
+                BerLength length = new BerLength();
+                codeLength += length.decode(is);
+                int totalLength = length.val;
+
+                while (subCodeLength < totalLength) {
+                    BerInteger element = new BerInteger();
+                    subCodeLength += element.decode(is, true);
+                    seqOf.add(element);
+                }
+                if (subCodeLength != totalLength) {
+                    throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+                }
+                codeLength += subCodeLength;
+
+                return codeLength;
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os, false);
+                code = os.getArray();
+            }
+
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                sb.append("{\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (seqOf == null) {
+                    sb.append("null");
+                } else {
+                    Iterator<BerInteger> it = seqOf.iterator();
+                    if (it.hasNext()) {
+                        sb.append(it.next());
+                        while (it.hasNext()) {
+                            sb.append(",\n");
+                            for (int i = 0; i < indentLevel + 1; i++) {
+                                sb.append("\t");
+                            }
+                            sb.append(it.next());
+                        }
+                    }
+                }
+
+                sb.append("\n");
+                for (int i = 0; i < indentLevel; i++) {
+                    sb.append("\t");
+                }
+                sb.append("}");
+            }
+
+        }
+
+        public static class Delmeasid implements Serializable {
+
+            public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+            private static final long serialVersionUID = 1L;
+            @JsonIgnore
+            public byte[] code = null;
+            private List<BerInteger> seqOf = null;
+
+            public Delmeasid() {
+                seqOf = new ArrayList<BerInteger>();
+            }
+
+            public Delmeasid(byte[] code) {
+                this.code = code;
+            }
+
+            @JsonValue
+            public List<BerInteger> getBerInteger() {
+                if (seqOf == null) {
+                    seqOf = new ArrayList<BerInteger>();
+                }
+                return seqOf;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+                return encode(os, true);
+            }
+
+            public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    if (withTag) {
+                        return tag.encode(os) + code.length;
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                    codeLength += seqOf.get(i).encode(os, true);
+                }
+
+                codeLength += BerLength.encodeLength(os, codeLength);
+
+                if (withTag) {
+                    codeLength += tag.encode(os);
+                }
+
+                return codeLength;
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, true);
+            }
+
+            public int decode(InputStream is, boolean withTag) throws IOException {
+                int codeLength = 0;
+                int subCodeLength = 0;
+                if (withTag) {
+                    codeLength += tag.decodeAndCheck(is);
+                }
+
+                BerLength length = new BerLength();
+                codeLength += length.decode(is);
+                int totalLength = length.val;
+
+                while (subCodeLength < totalLength) {
+                    BerInteger element = new BerInteger();
+                    subCodeLength += element.decode(is, true);
+                    seqOf.add(element);
+                }
+                if (subCodeLength != totalLength) {
+                    throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+                }
+                codeLength += subCodeLength;
+
+                return codeLength;
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os, false);
+                code = os.getArray();
+            }
+
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                sb.append("{\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (seqOf == null) {
+                    sb.append("null");
+                } else {
+                    Iterator<BerInteger> it = seqOf.iterator();
+                    if (it.hasNext()) {
+                        sb.append(it.next());
+                        while (it.hasNext()) {
+                            sb.append(",\n");
+                            for (int i = 0; i < indentLevel + 1; i++) {
+                                sb.append("\t");
+                            }
+                            sb.append(it.next());
+                        }
+                    }
+                }
+
+                sb.append("\n");
+                for (int i = 0; i < indentLevel; i++) {
+                    sb.append("\t");
+                }
+                sb.append("}");
+            }
+
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasObject.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasObject.java
new file mode 100644
index 0000000..7c9f73f
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/MeasObject.java
@@ -0,0 +1,328 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class MeasObject implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ARFCNValue dlFreq = null;
+    private MeasCells measCells = null;
+    public MeasObject() {
+    }
+
+    public MeasObject(byte[] code) {
+        this.code = code;
+    }
+
+    public ARFCNValue getDlFreq() {
+        return dlFreq;
+    }
+
+    public void setDlFreq(ARFCNValue dlFreq) {
+        this.dlFreq = dlFreq;
+    }
+
+    public MeasCells getMeasCells() {
+        return measCells;
+    }
+
+    public void setMeasCells(MeasCells measCells) {
+        this.measCells = measCells;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (measCells != null) {
+            codeLength += measCells.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += dlFreq.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            dlFreq = new ARFCNValue();
+            subCodeLength += dlFreq.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            measCells = new MeasCells();
+            subCodeLength += measCells.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (dlFreq != null) {
+            sb.append("dlFreq: ").append(dlFreq);
+        } else {
+            sb.append("dlFreq: <empty-required-field>");
+        }
+
+        if (measCells != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("measCells: ");
+            measCells.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class MeasCells implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private PhysCellId pci = null;
+        private QOffsetRange cellIndividualOffset = null;
+
+        public MeasCells() {
+        }
+
+        public MeasCells(byte[] code) {
+            this.code = code;
+        }
+
+        public PhysCellId getPci() {
+            return pci;
+        }
+
+        public void setPci(PhysCellId pci) {
+            this.pci = pci;
+        }
+
+        public QOffsetRange getCellIndividualOffset() {
+            return cellIndividualOffset;
+        }
+
+        public void setCellIndividualOffset(QOffsetRange cellIndividualOffset) {
+            this.cellIndividualOffset = cellIndividualOffset;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            if (cellIndividualOffset != null) {
+                codeLength += cellIndividualOffset.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+                os.write(0x81);
+                codeLength += 1;
+            }
+
+            codeLength += pci.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+            os.write(0x80);
+            codeLength += 1;
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            BerTag berTag = new BerTag();
+
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+
+            int totalLength = length.val;
+            codeLength += totalLength;
+
+            subCodeLength += berTag.decode(is);
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+                pci = new PhysCellId();
+                subCodeLength += pci.decode(is, false);
+                if (subCodeLength == totalLength) {
+                    return codeLength;
+                }
+                subCodeLength += berTag.decode(is);
+            } else {
+                throw new IOException("Tag does not match the mandatory sequence element tag.");
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+                cellIndividualOffset = new QOffsetRange();
+                subCodeLength += cellIndividualOffset.decode(is, false);
+                if (subCodeLength == totalLength) {
+                    return codeLength;
+                }
+            }
+            throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{");
+            sb.append("\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (pci != null) {
+                sb.append("pci: ").append(pci);
+            } else {
+                sb.append("pci: <empty-required-field>");
+            }
+
+            if (cellIndividualOffset != null) {
+                sb.append(",\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                sb.append("cellIndividualOffset: ").append(cellIndividualOffset);
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PCIARFCN.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PCIARFCN.java
new file mode 100644
index 0000000..5d50d9e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PCIARFCN.java
@@ -0,0 +1,184 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class PCIARFCN implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PhysCellId pci = null;
+    private ARFCNValue earfcnDl = null;
+
+    public PCIARFCN() {
+    }
+
+    public PCIARFCN(byte[] code) {
+        this.code = code;
+    }
+
+    public PhysCellId getPci() {
+        return pci;
+    }
+
+    public void setPci(PhysCellId pci) {
+        this.pci = pci;
+    }
+
+    public ARFCNValue getEarfcnDl() {
+        return earfcnDl;
+    }
+
+    public void setEarfcnDl(ARFCNValue earfcnDl) {
+        this.earfcnDl = earfcnDl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += earfcnDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += pci.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            pci = new PhysCellId();
+            subCodeLength += pci.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            earfcnDl = new ARFCNValue();
+            subCodeLength += earfcnDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pci != null) {
+            sb.append("pci: ").append(pci);
+        } else {
+            sb.append("pci: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (earfcnDl != null) {
+            sb.append("earfcnDl: ").append(earfcnDl);
+        } else {
+            sb.append("earfcnDl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof PCIARFCN) {
+            return pci.equals(((PCIARFCN) o).getPci()) && earfcnDl.equals(((PCIARFCN) o).getEarfcnDl());
+        }
+
+        return super.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+        int result = pci.hashCode();
+        result = 31 * result + earfcnDl.hashCode();
+        return result;
+    }
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PLMNIdentity.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PLMNIdentity.java
new file mode 100644
index 0000000..0d3a8c6
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PLMNIdentity.java
@@ -0,0 +1,35 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.util.Arrays;
+
+
+public class PLMNIdentity extends BerOctetString {
+
+    private static final long serialVersionUID = 1L;
+
+    public PLMNIdentity() {
+    }
+
+    public PLMNIdentity(byte[] value) {
+        super(value);
+    }
+
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(value);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof PLMNIdentity) {
+            return Arrays.equals(value, ((PLMNIdentity) obj).value);
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PRBUsage.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PRBUsage.java
new file mode 100644
index 0000000..c7d846a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PRBUsage.java
@@ -0,0 +1,426 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class PRBUsage implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PrbUsageDl prbUsageDl = null;
+    private PrbUsageUl prbUsageUl = null;
+    public PRBUsage() {
+    }
+    public PRBUsage(byte[] code) {
+        this.code = code;
+    }
+
+    public PrbUsageDl getPrbUsageDl() {
+        return prbUsageDl;
+    }
+
+    public void setPrbUsageDl(PrbUsageDl prbUsageDl) {
+        this.prbUsageDl = prbUsageDl;
+    }
+
+    public PrbUsageUl getPrbUsageUl() {
+        return prbUsageUl;
+    }
+
+    public void setPrbUsageUl(PrbUsageUl prbUsageUl) {
+        this.prbUsageUl = prbUsageUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += prbUsageUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += prbUsageDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            prbUsageDl = new PrbUsageDl();
+            subCodeLength += prbUsageDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            prbUsageUl = new PrbUsageUl();
+            subCodeLength += prbUsageUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (prbUsageDl != null) {
+            sb.append("prbUsageDl: ");
+            prbUsageDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("prbUsageDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (prbUsageUl != null) {
+            sb.append("prbUsageUl: ");
+            prbUsageUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("prbUsageUl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class PrbUsageDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PrbUsageDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PrbUsageDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PrbUsageUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PrbUsageUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PrbUsageUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PerParam.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PerParam.java
new file mode 100644
index 0000000..c287c2e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PerParam.java
@@ -0,0 +1,138 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class PerParam implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BerEnum reportIntervalMs = null;
+
+    public PerParam() {
+    }
+
+    public PerParam(byte[] code) {
+        this.code = code;
+    }
+
+    public BerEnum getReportIntervalMs() {
+        return reportIntervalMs;
+    }
+
+    public void setReportIntervalMs(BerEnum reportIntervalMs) {
+        this.reportIntervalMs = reportIntervalMs;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += reportIntervalMs.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            reportIntervalMs = new BerEnum();
+            subCodeLength += reportIntervalMs.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportIntervalMs != null) {
+            sb.append("reportIntervalMs: ").append(reportIntervalMs);
+        } else {
+            sb.append("reportIntervalMs: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PhysCellId.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PhysCellId.java
new file mode 100644
index 0000000..f875fee
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PhysCellId.java
@@ -0,0 +1,43 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class PhysCellId extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public PhysCellId() {
+    }
+
+    public PhysCellId(byte[] code) {
+        super(code);
+    }
+
+    public PhysCellId(BigInteger value) {
+        super(value);
+    }
+
+    public PhysCellId(long value) {
+        super(value);
+    }
+
+    @Override
+    public int hashCode() {
+        return value.intValue();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof PhysCellId) {
+            return value.intValue() == ((PhysCellId) obj).value.intValue();
+        }
+        return super.equals(obj);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PropScell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PropScell.java
new file mode 100644
index 0000000..7f84337
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/PropScell.java
@@ -0,0 +1,237 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class PropScell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PCIARFCN pciArfcn = null;
+    private BerBoolean crossCarrierSchedEnable = null;
+    private BerEnum caDirection = null;
+    private BerInteger deactTimer = null;
+
+    public PropScell() {
+    }
+
+    public PropScell(byte[] code) {
+        this.code = code;
+    }
+
+    public PCIARFCN getPciArfcn() {
+        return pciArfcn;
+    }
+
+    public void setPciArfcn(PCIARFCN pciArfcn) {
+        this.pciArfcn = pciArfcn;
+    }
+
+    public BerBoolean getCrossCarrierSchedEnable() {
+        return crossCarrierSchedEnable;
+    }
+
+    public void setCrossCarrierSchedEnable(BerBoolean crossCarrierSchedEnable) {
+        this.crossCarrierSchedEnable = crossCarrierSchedEnable;
+    }
+
+    public BerEnum getCaDirection() {
+        return caDirection;
+    }
+
+    public void setCaDirection(BerEnum caDirection) {
+        this.caDirection = caDirection;
+    }
+
+    public BerInteger getDeactTimer() {
+        return deactTimer;
+    }
+
+    public void setDeactTimer(BerInteger deactTimer) {
+        this.deactTimer = deactTimer;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += deactTimer.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += caDirection.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += crossCarrierSchedEnable.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += pciArfcn.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            pciArfcn = new PCIARFCN();
+            subCodeLength += pciArfcn.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            crossCarrierSchedEnable = new BerBoolean();
+            subCodeLength += crossCarrierSchedEnable.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            caDirection = new BerEnum();
+            subCodeLength += caDirection.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            deactTimer = new BerInteger();
+            subCodeLength += deactTimer.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pciArfcn != null) {
+            sb.append("pciArfcn: ");
+            pciArfcn.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pciArfcn: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crossCarrierSchedEnable != null) {
+            sb.append("crossCarrierSchedEnable: ").append(crossCarrierSchedEnable);
+        } else {
+            sb.append("crossCarrierSchedEnable: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (caDirection != null) {
+            sb.append("caDirection: ").append(caDirection);
+        } else {
+            sb.append("caDirection: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (deactTimer != null) {
+            sb.append("deactTimer: ").append(deactTimer);
+        } else {
+            sb.append("deactTimer: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QCI.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QCI.java
new file mode 100644
index 0000000..e8b2bee
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QCI.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class QCI extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public QCI() {
+    }
+
+    public QCI(byte[] code) {
+        super(code);
+    }
+
+    public QCI(BigInteger value) {
+        super(value);
+    }
+
+    public QCI(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QOffsetRange.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QOffsetRange.java
new file mode 100644
index 0000000..4eb2577
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/QOffsetRange.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class QOffsetRange extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public QOffsetRange() {
+    }
+
+    public QOffsetRange(byte[] code) {
+        super(code);
+    }
+
+    public QOffsetRange(BigInteger value) {
+        super(value);
+    }
+
+    public QOffsetRange(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRPRange.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRPRange.java
new file mode 100644
index 0000000..836d36b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRPRange.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class RSRPRange extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public RSRPRange() {
+    }
+
+    public RSRPRange(byte[] code) {
+        super(code);
+    }
+
+    public RSRPRange(BigInteger value) {
+        super(value);
+    }
+
+    public RSRPRange(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRQRange.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRQRange.java
new file mode 100644
index 0000000..f34b201
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RSRQRange.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.math.BigInteger;
+
+
+public class RSRQRange extends BerInteger {
+
+    private static final long serialVersionUID = 1L;
+
+    public RSRQRange() {
+    }
+
+    public RSRQRange(byte[] code) {
+        super(code);
+    }
+
+    public RSRQRange(BigInteger value) {
+        super(value);
+    }
+
+    public RSRQRange(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RXSigReport.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RXSigReport.java
new file mode 100644
index 0000000..afd630a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RXSigReport.java
@@ -0,0 +1,240 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class RXSigReport implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private PCIARFCN pciArfcn = null;
+    private ECGI ecgi = null;
+    private RSRPRange rsrp = null;
+    private RSRQRange rsrq = null;
+
+    public RXSigReport() {
+    }
+
+    public RXSigReport(byte[] code) {
+        this.code = code;
+    }
+
+    public PCIARFCN getPciArfcn() {
+        return pciArfcn;
+    }
+
+    public void setPciArfcn(PCIARFCN pciArfcn) {
+        this.pciArfcn = pciArfcn;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public RSRPRange getRsrp() {
+        return rsrp;
+    }
+
+    public void setRsrp(RSRPRange rsrp) {
+        this.rsrp = rsrp;
+    }
+
+    public RSRQRange getRsrq() {
+        return rsrq;
+    }
+
+    public void setRsrq(RSRQRange rsrq) {
+        this.rsrq = rsrq;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (rsrq != null) {
+            codeLength += rsrq.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+            os.write(0x83);
+            codeLength += 1;
+        }
+
+        if (rsrp != null) {
+            codeLength += rsrp.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+            os.write(0x82);
+            codeLength += 1;
+        }
+
+        if (ecgi != null) {
+            codeLength += ecgi.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += pciArfcn.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            pciArfcn = new PCIARFCN();
+            subCodeLength += pciArfcn.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            rsrp = new RSRPRange();
+            subCodeLength += rsrp.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            rsrq = new RSRQRange();
+            subCodeLength += rsrq.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pciArfcn != null) {
+            sb.append("pciArfcn: ");
+            pciArfcn.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pciArfcn: <empty-required-field>");
+        }
+
+        if (ecgi != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (rsrp != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("rsrp: ").append(rsrp);
+        }
+
+        if (rsrq != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("rsrq: ").append(rsrq);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RadioRepPerServCell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RadioRepPerServCell.java
new file mode 100644
index 0000000..e6607cf
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RadioRepPerServCell.java
@@ -0,0 +1,777 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class RadioRepPerServCell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private CqiHist cqiHist = null;
+    private RiHist riHist = null;
+    private PuschSinrHist puschSinrHist = null;
+    private PucchSinrHist pucchSinrHist = null;
+    public RadioRepPerServCell() {
+    }
+    public RadioRepPerServCell(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CqiHist getCqiHist() {
+        return cqiHist;
+    }
+
+    public void setCqiHist(CqiHist cqiHist) {
+        this.cqiHist = cqiHist;
+    }
+
+    public RiHist getRiHist() {
+        return riHist;
+    }
+
+    public void setRiHist(RiHist riHist) {
+        this.riHist = riHist;
+    }
+
+    public PuschSinrHist getPuschSinrHist() {
+        return puschSinrHist;
+    }
+
+    public void setPuschSinrHist(PuschSinrHist puschSinrHist) {
+        this.puschSinrHist = puschSinrHist;
+    }
+
+    public PucchSinrHist getPucchSinrHist() {
+        return pucchSinrHist;
+    }
+
+    public void setPucchSinrHist(PucchSinrHist pucchSinrHist) {
+        this.pucchSinrHist = pucchSinrHist;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += pucchSinrHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += puschSinrHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += riHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += cqiHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            cqiHist = new CqiHist();
+            subCodeLength += cqiHist.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            riHist = new RiHist();
+            subCodeLength += riHist.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            puschSinrHist = new PuschSinrHist();
+            subCodeLength += puschSinrHist.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            pucchSinrHist = new PucchSinrHist();
+            subCodeLength += pucchSinrHist.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (cqiHist != null) {
+            sb.append("cqiHist: ");
+            cqiHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("cqiHist: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (riHist != null) {
+            sb.append("riHist: ");
+            riHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("riHist: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (puschSinrHist != null) {
+            sb.append("puschSinrHist: ");
+            puschSinrHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("puschSinrHist: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pucchSinrHist != null) {
+            sb.append("pucchSinrHist: ");
+            pucchSinrHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pucchSinrHist: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class CqiHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public CqiHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public CqiHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class RiHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public RiHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public RiHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PuschSinrHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PuschSinrHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PuschSinrHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PucchSinrHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PucchSinrHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PucchSinrHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReconfIndReason.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReconfIndReason.java
new file mode 100644
index 0000000..54ebc11
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReconfIndReason.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class ReconfIndReason extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public ReconfIndReason() {
+    }
+
+    public ReconfIndReason(byte[] code) {
+        super(code);
+    }
+
+    public ReconfIndReason(BigInteger value) {
+        super(value);
+    }
+
+    public ReconfIndReason(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RelCause.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RelCause.java
new file mode 100644
index 0000000..eb4b62e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/RelCause.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class RelCause extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public RelCause() {
+    }
+
+    public RelCause(byte[] code) {
+        super(code);
+    }
+
+    public RelCause(BigInteger value) {
+        super(value);
+    }
+
+    public RelCause(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReportConfig.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReportConfig.java
new file mode 100644
index 0000000..c7314a6
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ReportConfig.java
@@ -0,0 +1,662 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class ReportConfig implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ReportParams reportParams = null;
+    private BerEnum triggerQuantity = null;
+    private BerEnum reportQuantity = null;
+    public ReportConfig() {
+    }
+
+    public ReportConfig(byte[] code) {
+        this.code = code;
+    }
+
+    public ReportParams getReportParams() {
+        return reportParams;
+    }
+
+    public void setReportParams(ReportParams reportParams) {
+        this.reportParams = reportParams;
+    }
+
+    public BerEnum getTriggerQuantity() {
+        return triggerQuantity;
+    }
+
+    public void setTriggerQuantity(BerEnum triggerQuantity) {
+        this.triggerQuantity = triggerQuantity;
+    }
+
+    public BerEnum getReportQuantity() {
+        return reportQuantity;
+    }
+
+    public void setReportQuantity(BerEnum reportQuantity) {
+        this.reportQuantity = reportQuantity;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += reportQuantity.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += triggerQuantity.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += reportParams.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            reportParams = new ReportParams();
+            subCodeLength += reportParams.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            triggerQuantity = new BerEnum();
+            subCodeLength += triggerQuantity.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            reportQuantity = new BerEnum();
+            subCodeLength += reportQuantity.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportParams != null) {
+            sb.append("reportParams: ");
+            reportParams.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("reportParams: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (triggerQuantity != null) {
+            sb.append("triggerQuantity: ").append(triggerQuantity);
+        } else {
+            sb.append("triggerQuantity: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportQuantity != null) {
+            sb.append("reportQuantity: ").append(reportQuantity);
+        } else {
+            sb.append("reportQuantity: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class ReportParams implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private Params params = null;
+        private Hysteresis hysteresis = null;
+        private TimeToTrigger timetotrigger = null;
+        public ReportParams() {
+        }
+
+        public ReportParams(byte[] code) {
+            this.code = code;
+        }
+
+        public Params getParams() {
+            return params;
+        }
+
+        public void setParams(Params params) {
+            this.params = params;
+        }
+
+        public Hysteresis getHysteresis() {
+            return hysteresis;
+        }
+
+        public void setHysteresis(Hysteresis hysteresis) {
+            this.hysteresis = hysteresis;
+        }
+
+        public TimeToTrigger getTimetotrigger() {
+            return timetotrigger;
+        }
+
+        public void setTimetotrigger(TimeToTrigger timetotrigger) {
+            this.timetotrigger = timetotrigger;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            int sublength;
+
+            codeLength += timetotrigger.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+            os.write(0x82);
+            codeLength += 1;
+
+            codeLength += hysteresis.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+            os.write(0x81);
+            codeLength += 1;
+
+            sublength = params.encode(os);
+            codeLength += sublength;
+            codeLength += BerLength.encodeLength(os, sublength);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+            os.write(0xA0);
+            codeLength += 1;
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            BerTag berTag = new BerTag();
+
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+
+            int totalLength = length.val;
+            codeLength += totalLength;
+
+            subCodeLength += berTag.decode(is);
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+                subCodeLength += length.decode(is);
+                params = new Params();
+                subCodeLength += params.decode(is, null);
+                subCodeLength += berTag.decode(is);
+            } else {
+                throw new IOException("Tag does not match the mandatory sequence element tag.");
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+                hysteresis = new Hysteresis();
+                subCodeLength += hysteresis.decode(is, false);
+                subCodeLength += berTag.decode(is);
+            } else {
+                throw new IOException("Tag does not match the mandatory sequence element tag.");
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+                timetotrigger = new TimeToTrigger();
+                subCodeLength += timetotrigger.decode(is, false);
+                if (subCodeLength == totalLength) {
+                    return codeLength;
+                }
+            }
+            throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{");
+            sb.append("\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (params != null) {
+                sb.append("params: ");
+                params.appendAsString(sb, indentLevel + 1);
+            } else {
+                sb.append("params: <empty-required-field>");
+            }
+
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (hysteresis != null) {
+                sb.append("hysteresis: ").append(hysteresis);
+            } else {
+                sb.append("hysteresis: <empty-required-field>");
+            }
+
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (timetotrigger != null) {
+                sb.append("timetotrigger: ").append(timetotrigger);
+            } else {
+                sb.append("timetotrigger: <empty-required-field>");
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+        public static class Params implements Serializable {
+
+            private static final long serialVersionUID = 1L;
+
+            @JsonIgnore
+            public byte[] code = null;
+            private PerParam perParam = null;
+            private A1Param a1param = null;
+            private A2Param a2param = null;
+            private A3Param a3param = null;
+            private A4Param a4param = null;
+            private A5Param a5param = null;
+            private A6Param a6param = null;
+
+            public Params() {
+            }
+
+            public Params(byte[] code) {
+                this.code = code;
+            }
+
+            public PerParam getPerParam() {
+                return perParam;
+            }
+
+            public void setPerParam(PerParam perParam) {
+                this.perParam = perParam;
+            }
+
+            public A1Param getA1param() {
+                return a1param;
+            }
+
+            public void setA1param(A1Param a1param) {
+                this.a1param = a1param;
+            }
+
+            public A2Param getA2param() {
+                return a2param;
+            }
+
+            public void setA2param(A2Param a2param) {
+                this.a2param = a2param;
+            }
+
+            public A3Param getA3param() {
+                return a3param;
+            }
+
+            public void setA3param(A3Param a3param) {
+                this.a3param = a3param;
+            }
+
+            public A4Param getA4param() {
+                return a4param;
+            }
+
+            public void setA4param(A4Param a4param) {
+                this.a4param = a4param;
+            }
+
+            public A5Param getA5param() {
+                return a5param;
+            }
+
+            public void setA5param(A5Param a5param) {
+                this.a5param = a5param;
+            }
+
+            public A6Param getA6param() {
+                return a6param;
+            }
+
+            public void setA6param(A6Param a6param) {
+                this.a6param = a6param;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                if (a6param != null) {
+                    codeLength += a6param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 6
+                    os.write(0xA6);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (a5param != null) {
+                    codeLength += a5param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 5
+                    os.write(0xA5);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (a4param != null) {
+                    codeLength += a4param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+                    os.write(0xA4);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (a3param != null) {
+                    codeLength += a3param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+                    os.write(0xA3);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (a2param != null) {
+                    codeLength += a2param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+                    os.write(0xA2);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (a1param != null) {
+                    codeLength += a1param.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+                    os.write(0xA1);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                if (perParam != null) {
+                    codeLength += perParam.encode(os, false);
+                    // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+                    os.write(0xA0);
+                    codeLength += 1;
+                    return codeLength;
+                }
+
+                throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, null);
+            }
+
+            public int decode(InputStream is, BerTag berTag) throws IOException {
+
+                int codeLength = 0;
+                BerTag passedTag = berTag;
+
+                if (berTag == null) {
+                    berTag = new BerTag();
+                    codeLength += berTag.decode(is);
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+                    perParam = new PerParam();
+                    codeLength += perParam.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+                    a1param = new A1Param();
+                    codeLength += a1param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+                    a2param = new A2Param();
+                    codeLength += a2param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+                    a3param = new A3Param();
+                    codeLength += a3param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+                    a4param = new A4Param();
+                    codeLength += a4param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
+                    a5param = new A5Param();
+                    codeLength += a5param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) {
+                    a6param = new A6Param();
+                    codeLength += a6param.decode(is, false);
+                    return codeLength;
+                }
+
+                if (passedTag != null) {
+                    return 0;
+                }
+
+                throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os);
+                code = os.getArray();
+            }
+
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                if (perParam != null) {
+                    sb.append("perParam: ");
+                    perParam.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a1param != null) {
+                    sb.append("a1param: ");
+                    a1param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a2param != null) {
+                    sb.append("a2param: ");
+                    a2param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a3param != null) {
+                    sb.append("a3param: ");
+                    a3param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a4param != null) {
+                    sb.append("a4param: ");
+                    a4param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a5param != null) {
+                    sb.append("a5param: ");
+                    a5param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                if (a6param != null) {
+                    sb.append("a6param: ");
+                    a6param.appendAsString(sb, indentLevel + 1);
+                    return;
+                }
+
+                sb.append("<none>");
+            }
+
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/SchedMeasRepPerServCell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/SchedMeasRepPerServCell.java
new file mode 100644
index 0000000..a367b9b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/SchedMeasRepPerServCell.java
@@ -0,0 +1,1287 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class SchedMeasRepPerServCell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private QciVals qciVals = null;
+    private PRBUsage prbUsage = null;
+    private McsDl mcsDl = null;
+    private NumSchedTtisDl numSchedTtisDl = null;
+    private McsUl mcsUl = null;
+    private NumSchedTtisUl numSchedTtisUl = null;
+    private RankDl1 rankDl1 = null;
+    private RankDl2 rankDl2 = null;
+    public SchedMeasRepPerServCell() {
+    }
+    public SchedMeasRepPerServCell(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public QciVals getQciVals() {
+        return qciVals;
+    }
+
+    public void setQciVals(QciVals qciVals) {
+        this.qciVals = qciVals;
+    }
+
+    public PRBUsage getPrbUsage() {
+        return prbUsage;
+    }
+
+    public void setPrbUsage(PRBUsage prbUsage) {
+        this.prbUsage = prbUsage;
+    }
+
+    public McsDl getMcsDl() {
+        return mcsDl;
+    }
+
+    public void setMcsDl(McsDl mcsDl) {
+        this.mcsDl = mcsDl;
+    }
+
+    public NumSchedTtisDl getNumSchedTtisDl() {
+        return numSchedTtisDl;
+    }
+
+    public void setNumSchedTtisDl(NumSchedTtisDl numSchedTtisDl) {
+        this.numSchedTtisDl = numSchedTtisDl;
+    }
+
+    public McsUl getMcsUl() {
+        return mcsUl;
+    }
+
+    public void setMcsUl(McsUl mcsUl) {
+        this.mcsUl = mcsUl;
+    }
+
+    public NumSchedTtisUl getNumSchedTtisUl() {
+        return numSchedTtisUl;
+    }
+
+    public void setNumSchedTtisUl(NumSchedTtisUl numSchedTtisUl) {
+        this.numSchedTtisUl = numSchedTtisUl;
+    }
+
+    public RankDl1 getRankDl1() {
+        return rankDl1;
+    }
+
+    public void setRankDl1(RankDl1 rankDl1) {
+        this.rankDl1 = rankDl1;
+    }
+
+    public RankDl2 getRankDl2() {
+        return rankDl2;
+    }
+
+    public void setRankDl2(RankDl2 rankDl2) {
+        this.rankDl2 = rankDl2;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += rankDl2.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 8
+        os.write(0xA8);
+        codeLength += 1;
+
+        codeLength += rankDl1.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 7
+        os.write(0xA7);
+        codeLength += 1;
+
+        codeLength += numSchedTtisUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 6
+        os.write(0xA6);
+        codeLength += 1;
+
+        codeLength += mcsUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 5
+        os.write(0xA5);
+        codeLength += 1;
+
+        codeLength += numSchedTtisDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += mcsDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += prbUsage.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += qciVals.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            qciVals = new QciVals();
+            subCodeLength += qciVals.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            prbUsage = new PRBUsage();
+            subCodeLength += prbUsage.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            mcsDl = new McsDl();
+            subCodeLength += mcsDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            numSchedTtisDl = new NumSchedTtisDl();
+            subCodeLength += numSchedTtisDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
+            mcsUl = new McsUl();
+            subCodeLength += mcsUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) {
+            numSchedTtisUl = new NumSchedTtisUl();
+            subCodeLength += numSchedTtisUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) {
+            rankDl1 = new RankDl1();
+            subCodeLength += rankDl1.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
+            rankDl2 = new RankDl2();
+            subCodeLength += rankDl2.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (qciVals != null) {
+            sb.append("qciVals: ");
+            qciVals.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("qciVals: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (prbUsage != null) {
+            sb.append("prbUsage: ");
+            prbUsage.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("prbUsage: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mcsDl != null) {
+            sb.append("mcsDl: ");
+            mcsDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("mcsDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numSchedTtisDl != null) {
+            sb.append("numSchedTtisDl: ");
+            numSchedTtisDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("numSchedTtisDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mcsUl != null) {
+            sb.append("mcsUl: ");
+            mcsUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("mcsUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numSchedTtisUl != null) {
+            sb.append("numSchedTtisUl: ");
+            numSchedTtisUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("numSchedTtisUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (rankDl1 != null) {
+            sb.append("rankDl1: ");
+            rankDl1.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("rankDl1: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (rankDl2 != null) {
+            sb.append("rankDl2: ");
+            rankDl2.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("rankDl2: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class QciVals implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<QCI> seqOf = null;
+
+        public QciVals() {
+            seqOf = new ArrayList<QCI>();
+        }
+
+        public QciVals(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<QCI> getQCI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<QCI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                QCI element = new QCI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<QCI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class McsDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public McsDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public McsDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class NumSchedTtisDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public NumSchedTtisDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public NumSchedTtisDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class McsUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public McsUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public McsUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class NumSchedTtisUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public NumSchedTtisUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public NumSchedTtisUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class RankDl1 implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public RankDl1() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public RankDl1(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class RankDl2 implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public RankDl2() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public RankDl2(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ThresholdEUTRA.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ThresholdEUTRA.java
new file mode 100644
index 0000000..18f8f0c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/ThresholdEUTRA.java
@@ -0,0 +1,138 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class ThresholdEUTRA implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @JsonIgnore
+    public byte[] code = null;
+    private RSRPRange thresholdRSRP = null;
+    private RSRQRange thresholdRSRQ = null;
+
+    public ThresholdEUTRA() {
+    }
+
+    public ThresholdEUTRA(byte[] code) {
+        this.code = code;
+    }
+
+    public RSRPRange getThresholdRSRP() {
+        return thresholdRSRP;
+    }
+
+    public void setThresholdRSRP(RSRPRange thresholdRSRP) {
+        this.thresholdRSRP = thresholdRSRP;
+    }
+
+    public RSRQRange getThresholdRSRQ() {
+        return thresholdRSRQ;
+    }
+
+    public void setThresholdRSRQ(RSRQRange thresholdRSRQ) {
+        this.thresholdRSRQ = thresholdRSRQ;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (thresholdRSRQ != null) {
+            codeLength += thresholdRSRQ.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+            os.write(0x81);
+            codeLength += 1;
+            return codeLength;
+        }
+
+        if (thresholdRSRP != null) {
+            codeLength += thresholdRSRP.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+            os.write(0x80);
+            codeLength += 1;
+            return codeLength;
+        }
+
+        throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, null);
+    }
+
+    public int decode(InputStream is, BerTag berTag) throws IOException {
+
+        int codeLength = 0;
+        BerTag passedTag = berTag;
+
+        if (berTag == null) {
+            berTag = new BerTag();
+            codeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            thresholdRSRP = new RSRPRange();
+            codeLength += thresholdRSRP.decode(is, false);
+            return codeLength;
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            thresholdRSRQ = new RSRQRange();
+            codeLength += thresholdRSRQ.decode(is, false);
+            return codeLength;
+        }
+
+        if (passedTag != null) {
+            return 0;
+        }
+
+        throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        if (thresholdRSRP != null) {
+            sb.append("thresholdRSRP: ").append(thresholdRSRP);
+            return;
+        }
+
+        if (thresholdRSRQ != null) {
+            sb.append("thresholdRSRQ: ").append(thresholdRSRQ);
+            return;
+        }
+
+        sb.append("<none>");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TimeToTrigger.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TimeToTrigger.java
new file mode 100644
index 0000000..fe042ec
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TimeToTrigger.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class TimeToTrigger extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public TimeToTrigger() {
+    }
+
+    public TimeToTrigger(byte[] code) {
+        super(code);
+    }
+
+    public TimeToTrigger(BigInteger value) {
+        super(value);
+    }
+
+    public TimeToTrigger(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TrafficSplitPercentage.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TrafficSplitPercentage.java
new file mode 100644
index 0000000..e0599c0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/TrafficSplitPercentage.java
@@ -0,0 +1,207 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class TrafficSplitPercentage implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private BerInteger trafficPercentDl = null;
+    private BerInteger trafficPercentUl = null;
+
+    public TrafficSplitPercentage() {
+    }
+
+    public TrafficSplitPercentage(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public BerInteger getTrafficPercentDl() {
+        return trafficPercentDl;
+    }
+
+    public void setTrafficPercentDl(BerInteger trafficPercentDl) {
+        this.trafficPercentDl = trafficPercentDl;
+    }
+
+    public BerInteger getTrafficPercentUl() {
+        return trafficPercentUl;
+    }
+
+    public void setTrafficPercentUl(BerInteger trafficPercentUl) {
+        this.trafficPercentUl = trafficPercentUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (trafficPercentUl != null) {
+            codeLength += trafficPercentUl.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+            os.write(0x82);
+            codeLength += 1;
+        }
+
+        if (trafficPercentDl != null) {
+            codeLength += trafficPercentDl.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+            os.write(0x81);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            trafficPercentDl = new BerInteger();
+            subCodeLength += trafficPercentDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            trafficPercentUl = new BerInteger();
+            subCodeLength += trafficPercentUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (trafficPercentDl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("trafficPercentDl: ").append(trafficPercentDl);
+        }
+
+        if (trafficPercentUl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("trafficPercentUl: ").append(trafficPercentUl);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/UEAMBR.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/UEAMBR.java
new file mode 100644
index 0000000..3590d09
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/UEAMBR.java
@@ -0,0 +1,169 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class UEAMBR implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private BitRate ambrDl = null;
+    private BitRate ambrUl = null;
+
+    public UEAMBR() {
+    }
+
+    public UEAMBR(byte[] code) {
+        this.code = code;
+    }
+
+    public BitRate getAmbrDl() {
+        return ambrDl;
+    }
+
+    public void setAmbrDl(BitRate ambrDl) {
+        this.ambrDl = ambrDl;
+    }
+
+    public BitRate getAmbrUl() {
+        return ambrUl;
+    }
+
+    public void setAmbrUl(BitRate ambrUl) {
+        this.ambrUl = ambrUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += ambrUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += ambrDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            ambrDl = new BitRate();
+            subCodeLength += ambrDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            ambrUl = new BitRate();
+            subCodeLength += ambrUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ambrDl != null) {
+            sb.append("ambrDl: ").append(ambrDl);
+        } else {
+            sb.append("ambrDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ambrUl != null) {
+            sb.append("ambrUl: ").append(ambrUl);
+        } else {
+            sb.append("ambrUl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/XICICPA.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/XICICPA.java
new file mode 100644
index 0000000..431a1c9
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/api/XICICPA.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.api;
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+
+public class XICICPA extends BerEnum {
+
+    private static final long serialVersionUID = 1L;
+
+    public XICICPA() {
+    }
+
+    public XICICPA(byte[] code) {
+        super(code);
+    }
+
+    public XICICPA(BigInteger value) {
+        super(value);
+    }
+
+    public XICICPA(long value) {
+        super(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerByteArrayOutputStream.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerByteArrayOutputStream.java
new file mode 100644
index 0000000..a77e51d
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerByteArrayOutputStream.java
@@ -0,0 +1,115 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+public class BerByteArrayOutputStream extends OutputStream {
+
+    private final boolean automaticResize;
+    public byte[] buffer;
+    public int index;
+
+    /**
+     * Creates a <code>BerByteArrayOutputStream</code> with a byte array of size <code>bufferSize</code>. The buffer
+     * will not be resized automatically. Use {@link #BerByteArrayOutputStream(int, boolean)} instead if you want the
+     * buffer to be dynamically resized.
+     *
+     * @param bufferSize the size of the underlying buffer
+     */
+    public BerByteArrayOutputStream(int bufferSize) {
+        this(new byte[bufferSize], bufferSize - 1, false);
+    }
+
+    public BerByteArrayOutputStream(int bufferSize, boolean automaticResize) {
+        this(new byte[bufferSize], bufferSize - 1, automaticResize);
+    }
+
+    public BerByteArrayOutputStream(byte[] buffer) {
+        this(buffer, buffer.length - 1, false);
+    }
+
+    public BerByteArrayOutputStream(byte[] buffer, int startingIndex) {
+        this(buffer, startingIndex, false);
+    }
+
+    public BerByteArrayOutputStream(byte[] buffer, int startingIndex, boolean automaticResize) {
+        if (buffer.length <= 0) {
+            throw new IllegalArgumentException("buffer size may not be <= 0");
+        }
+        this.buffer = buffer;
+        index = startingIndex;
+        this.automaticResize = automaticResize;
+    }
+
+    @Override
+    public void write(int arg0) throws IOException {
+        write((byte) arg0);
+    }
+
+    public void write(byte arg0) throws IOException {
+        try {
+            buffer[index] = arg0;
+        } catch (ArrayIndexOutOfBoundsException e) {
+            if (automaticResize) {
+                resize();
+                buffer[index] = arg0;
+            } else {
+                throw new ArrayIndexOutOfBoundsException("buffer.length = " + buffer.length);
+            }
+        }
+        index--;
+    }
+
+    private void resize() {
+        byte[] newBuffer = new byte[buffer.length * 2];
+        System.arraycopy(buffer, index + 1, newBuffer, buffer.length + index + 1, buffer.length - index - 1);
+        index += buffer.length;
+        buffer = newBuffer;
+
+    }
+
+    @Override
+    public void write(byte[] byteArray) throws IOException {
+        for (int i = byteArray.length - 1; i >= 0; i--) {
+            try {
+                buffer[index] = byteArray[i];
+            } catch (ArrayIndexOutOfBoundsException e) {
+                if (automaticResize) {
+                    resize();
+                    buffer[index] = byteArray[i];
+                } else {
+                    throw new ArrayIndexOutOfBoundsException("buffer.length = " + buffer.length);
+                }
+            }
+            index--;
+        }
+    }
+
+    /**
+     * Returns a new array containing the subarray of the stream array that contains the coded content.
+     *
+     * @return a new array containing the subarray of the stream array
+     */
+    public byte[] getArray() {
+        if (index == -1) {
+            return buffer;
+        }
+        int subBufferLength = buffer.length - index - 1;
+        byte[] subBuffer = new byte[subBufferLength];
+        System.arraycopy(buffer, index + 1, subBuffer, 0, subBufferLength);
+        return subBuffer;
+
+    }
+
+    public ByteBuffer getByteBuffer() {
+        return ByteBuffer.wrap(buffer, index + 1, buffer.length - (index + 1));
+    }
+
+    public void reset() {
+        index = buffer.length - 1;
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerLength.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerLength.java
new file mode 100644
index 0000000..5bb87b9
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerLength.java
@@ -0,0 +1,115 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerLength implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public int val;
+
+    public BerLength() {
+    }
+
+    public static int skip(InputStream is) throws IOException {
+
+        int val = is.read();
+        if (val == -1) {
+            throw new EOFException("Unexpected end of input stream.");
+        }
+
+        if ((val & 0x80) == 0) {
+            return 1;
+        }
+
+        int lengthLength = val & 0x7f;
+
+        // check for indefinite length
+        if (lengthLength == 0) {
+            val = -1;
+            return 1;
+        }
+
+        if (lengthLength > 4) {
+            throw new IOException("Length is out of bound!");
+        }
+
+        for (int i = 0; i < lengthLength; i++) {
+            int nextByte = is.read();
+            if (nextByte == -1) {
+                throw new EOFException("Unexpected end of input stream.");
+            }
+        }
+
+        return lengthLength + 1;
+    }
+
+    public static int encodeLength(BerByteArrayOutputStream os, int length) throws IOException {
+        // the indefinite form is ignored for now
+
+        if (length <= 127) {
+            // this is the short form, it is coded differently than the long
+            // form for values > 127
+            os.write((byte) length);
+            return 1;
+        } else {
+            int numLengthBytes = 1;
+
+            while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) {
+                numLengthBytes++;
+            }
+
+            for (int i = 0; i < numLengthBytes; i++) {
+                os.write((length >> 8 * i) & 0xff);
+            }
+
+            os.write(0x80 | numLengthBytes);
+
+            return 1 + numLengthBytes;
+        }
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+
+        val = is.read();
+        if (val == -1) {
+            throw new EOFException("Unexpected end of input stream.");
+        }
+
+        if ((val & 0x80) == 0) {
+            return 1;
+        }
+
+        int lengthLength = val & 0x7f;
+
+        // check for indefinite length
+        if (lengthLength == 0) {
+            val = -1;
+            return 1;
+        }
+
+        if (lengthLength > 4) {
+            throw new IOException("Length is out of bound!");
+        }
+
+        val = 0;
+
+        for (int i = 0; i < lengthLength; i++) {
+            int nextByte = is.read();
+            if (nextByte == -1) {
+                throw new EOFException("Unexpected end of input stream.");
+            }
+            val |= nextByte << (8 * (lengthLength - i - 1));
+        }
+
+        return lengthLength + 1;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerTag.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerTag.java
new file mode 100644
index 0000000..4e9bc12
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/BerTag.java
@@ -0,0 +1,186 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerTag implements Serializable {
+
+    public static final int UNIVERSAL_CLASS = 0x00;
+    public static final int APPLICATION_CLASS = 0x40;
+    public static final int CONTEXT_CLASS = 0x80;
+    public static final int PRIVATE_CLASS = 0xc0;
+    public static final int PRIMITIVE = 0x00;
+    public static final int CONSTRUCTED = 0x20;
+    public static final int BOOLEAN_TAG = 1;
+    public static final int INTEGER_TAG = 2;
+    public static final int BIT_STRING_TAG = 3;
+    public static final int OCTET_STRING_TAG = 4;
+    public static final int NULL_TAG = 5;
+    public static final int OBJECT_IDENTIFIER_TAG = 6;
+    public static final int OBJECT_DESCRIPTOR_TAG = 7;
+    public static final int REAL_TAG = 9;
+    public static final int ENUMERATED_TAG = 10;
+    public static final int EMBEDDED_PDV_TAG = 11;
+    public static final int UTF8_STRING_TAG = 12;
+    public static final int TIME_TAG = 14;
+    public static final int NUMERIC_STRING_TAG = 18;
+    public static final int PRINTABLE_STRING_TAG = 19;
+    public static final int TELETEX_STRING_TAG = 20;
+    public static final int VIDEOTEX_STRING_TAG = 21;
+    public static final int IA5_STRING_TAG = 22;
+    public static final int UTC_TIME_TAG = 23;
+    public static final int GENERALIZED_TIME_TAG = 24;
+    public static final int GRAPHIC_STRING_TAG = 25;
+    public static final int VISIBLE_STRING_TAG = 26;
+    public static final int GENERAL_STRING_TAG = 27;
+    public static final int UNIVERSAL_STRING_TAG = 28;
+    public static final int BMP_STRING_TAG = 30;
+    public static final int DATE_TAG = 31;
+    public static final int TIME_OF_DAY_TAG = 32;
+    public static final int DATE_TIME_TAG = 33;
+    public static final int DURATION_TAG = 34;
+    private static final long serialVersionUID = 1L;
+    public byte[] tagBytes = null;
+    public int tagClass;
+    public int primitive;
+    public int tagNumber;
+
+    public BerTag(int identifierClass, int primitive, int tagNumber) {
+        this.tagClass = identifierClass;
+        this.primitive = primitive;
+        this.tagNumber = tagNumber;
+        code();
+    }
+
+    public BerTag() {
+    }
+
+    private void code() {
+        if (tagNumber < 31) {
+            tagBytes = new byte[1];
+            tagBytes[0] = (byte) (tagClass | primitive | tagNumber);
+        } else {
+            int tagLength = 1;
+            while (tagNumber > (Math.pow(2, (7 * tagLength)) - 1)) {
+                tagLength++;
+            }
+
+            tagBytes = new byte[1 + tagLength];
+            tagBytes[0] = (byte) (tagClass | primitive | 31);
+
+            for (int j = 1; j <= (tagLength - 1); j++) {
+                tagBytes[j] = (byte) (((tagNumber >> (7 * (tagLength - j))) & 0xff) | 0x80);
+            }
+
+            tagBytes[tagLength] = (byte) (tagNumber & 0x7f);
+
+        }
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        if (tagBytes == null) {
+            code();
+        }
+        for (int i = (tagBytes.length - 1); i >= 0; i--) {
+            os.write(tagBytes[i]);
+        }
+        return tagBytes.length;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        int nextByte = is.read();
+        if (nextByte == -1) {
+            throw new EOFException("Unexpected end of input stream.");
+        }
+
+        tagClass = nextByte & 0xC0;
+        primitive = nextByte & 0x20;
+        tagNumber = nextByte & 0x1f;
+
+        int codeLength = 1;
+
+        if (tagNumber == 0x1f) {
+            tagNumber = 0;
+
+            int counter = 0;
+
+            do {
+                nextByte = is.read();
+                if (nextByte == -1) {
+                    throw new EOFException("Unexpected end of input stream.");
+                }
+
+                codeLength++;
+                if (counter >= 6) {
+                    throw new IOException("Invalid Tag");
+                }
+                tagNumber = tagNumber << 7;
+                tagNumber |= (nextByte & 0x7f);
+                counter++;
+            } while ((nextByte & 0x80) == 0x80);
+
+        }
+
+        return codeLength;
+    }
+
+    /**
+     * Decodes the Identifier from the ByteArrayInputStream and throws an Exception if it is not equal to itself.
+     * Returns the number of bytes read from the InputStream.
+     *
+     * @param is the input stream to read the identifier from.
+     * @return the length of the identifier read.
+     * @throws IOException if an exception occurs reading the identifier from the stream.
+     */
+    public int decodeAndCheck(InputStream is) throws IOException {
+
+        for (Byte identifierByte : tagBytes) {
+            int nextByte = is.read();
+            if (nextByte == -1) {
+                throw new EOFException("Unexpected end of input stream.");
+            }
+
+            if (nextByte != (identifierByte & 0xff)) {
+                throw new IOException("Identifier does not match!");
+            }
+        }
+        return tagBytes.length;
+    }
+
+    public boolean equals(int identifierClass, int primitive, int tagNumber) {
+        return (this.tagNumber == tagNumber && this.tagClass == identifierClass && this.primitive == primitive);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof BerTag)) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        BerTag berIdentifier = (BerTag) obj;
+        return (tagNumber == berIdentifier.tagNumber && tagClass == berIdentifier.tagClass
+                && primitive == berIdentifier.primitive);
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 17;
+        hash = hash * 31 + tagNumber;
+        hash = hash * 31 + tagClass;
+        hash = hash * 31 + primitive;
+        return hash;
+    }
+
+    @Override
+    public String toString() {
+        return "identifier class: " + tagClass + ", primitive: " + primitive + ", tag number: " + tagNumber;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/internal/Util.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/internal/Util.java
new file mode 100644
index 0000000..b85b6ac
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/internal/Util.java
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.internal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class Util {
+
+    public static void readFully(InputStream is, byte[] buffer) throws IOException {
+        readFully(is, buffer, 0, buffer.length);
+    }
+
+    public static void readFully(InputStream is, byte[] buffer, int off, int len) throws IOException {
+        do {
+            int bytesRead = is.read(buffer, off, len);
+            if (bytesRead == -1) {
+                throw new EOFException("Unexpected end of input stream.");
+            }
+
+            len -= bytesRead;
+            off += bytesRead;
+        } while (len > 0);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerAny.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerAny.java
new file mode 100644
index 0000000..6445862
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerAny.java
@@ -0,0 +1,74 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerAny implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public byte[] value;
+
+    public BerAny() {
+    }
+
+    public BerAny(byte[] value) {
+        this.value = value;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        os.write(value);
+        return value.length;
+    }
+
+    public int decode(InputStream is) throws IOException {
+
+        return decode(is, null);
+    }
+
+    public int decode(InputStream is, BerTag tag) throws IOException {
+
+        int decodedLength = 0;
+
+        int tagLength;
+
+        if (tag == null) {
+            tag = new BerTag();
+            tagLength = tag.decode(is);
+            decodedLength += tagLength;
+        } else {
+            tagLength = tag.encode(new BerByteArrayOutputStream(10));
+        }
+
+        BerLength lengthField = new BerLength();
+        int lengthLength = lengthField.decode(is);
+        decodedLength += lengthLength + lengthField.val;
+
+        value = new byte[tagLength + lengthLength + lengthField.val];
+
+        Util.readFully(is, value, tagLength + lengthLength, lengthField.val);
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(value, tagLength + lengthLength - 1);
+        BerLength.encodeLength(os, lengthField.val);
+        tag.encode(os);
+
+        return decodedLength;
+    }
+
+    @JsonValue
+    @Override
+    public String toString() {
+        return DatatypeConverter.printHexBinary(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBitString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBitString.java
new file mode 100644
index 0000000..65b1e48
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBitString.java
@@ -0,0 +1,130 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerBitString implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.BIT_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public byte[] value;
+    @JsonIgnore public int numBits;
+
+    public BerBitString() {
+    }
+
+    public BerBitString(byte[] value, int numBits) {
+
+        if (value == null) {
+            throw new NullPointerException("value cannot be null");
+        }
+        if (numBits < 0) {
+            throw new IllegalArgumentException("numBits cannot be negative.");
+        }
+        if (numBits > (value.length * 8)) {
+            throw new IllegalArgumentException("'value' is too short to hold all bits.");
+        }
+
+        this.value = value;
+        this.numBits = numBits;
+
+    }
+
+    public BerBitString(byte[] code) {
+        this.code = code;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        for (int i = (value.length - 1); i >= 0; i--) {
+            os.write(value[i]);
+        }
+        os.write(value.length * 8 - numBits);
+
+        int codeLength = value.length + 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        // could be encoded in primitiv and constructed mode
+        // only primitiv mode is implemented
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        value = new byte[length.val - 1];
+
+        int unusedBits = is.read();
+        if (unusedBits == -1) {
+            throw new EOFException("Unexpected end of input stream.");
+        }
+        if (unusedBits > 7) {
+            throw new IOException(
+                    "Number of unused bits in bit string expected to be less than 8 but is: " + unusedBits);
+        }
+
+        numBits = (value.length * 8) - unusedBits;
+
+        if (value.length > 0) {
+            Util.readFully(is, value);
+        }
+
+        codeLength += value.length + 1;
+
+        return codeLength;
+
+    }
+
+    @JsonValue
+    @Override
+    public String toString() {
+        return DatatypeConverter.printHexBinary(value);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBoolean.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBoolean.java
new file mode 100644
index 0000000..34a26af
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerBoolean.java
@@ -0,0 +1,115 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerBoolean implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.BOOLEAN_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public boolean value;
+
+    public BerBoolean() {
+    }
+
+    public BerBoolean(byte[] code) {
+        this.code = code;
+    }
+
+    public BerBoolean(boolean value) {
+        this.value = value;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 1;
+
+        if (value) {
+            os.write(0xff);
+        } else {
+            os.write(0);
+        }
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        if (length.val != 1) {
+            throw new IOException("Decoded length of BerBoolean is not correct");
+        }
+
+        int nextByte = is.read();
+        if (nextByte == -1) {
+            throw new EOFException("Unexpected end of input stream.");
+        }
+
+        codeLength++;
+        if (nextByte == 0) {
+            value = false;
+        } else {
+            value = true;
+        }
+
+        return codeLength;
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    @JsonValue
+    @Override
+    public String toString() {
+        return "" + value;
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDate.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDate.java
new file mode 100644
index 0000000..e0548cb
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDate.java
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerDate extends BerTime {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.DATE_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerDate() {
+    }
+
+    public BerDate(byte[] value) {
+        super(value);
+    }
+
+    public BerDate(String valueAsString) throws UnsupportedEncodingException {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDateTime.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDateTime.java
new file mode 100644
index 0000000..cab9d98
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDateTime.java
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerDateTime extends BerTime {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.DATE_TIME_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerDateTime() {
+    }
+
+    public BerDateTime(byte[] value) {
+        super(value);
+    }
+
+    public BerDateTime(String valueAsString) throws UnsupportedEncodingException {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDuration.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDuration.java
new file mode 100644
index 0000000..1362547
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerDuration.java
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerDuration extends BerTime {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.DURATION_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerDuration() {
+    }
+
+    public BerDuration(byte[] value) {
+        super(value);
+    }
+
+    public BerDuration(String valueAsString) throws UnsupportedEncodingException {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEmbeddedPdv.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEmbeddedPdv.java
new file mode 100644
index 0000000..6156edc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEmbeddedPdv.java
@@ -0,0 +1,747 @@
+/**
+ * This class file was automatically generated by jASN1 v1.7.2-SNAPSHOT (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerObjectDescriptor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerEmbeddedPdv implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 11);
+    private static final long serialVersionUID = 1L;
+     @JsonIgnore public byte[] code = null;
+    private Identification identification = null;
+    private BerObjectDescriptor dataValueDescriptor = null;
+    private BerOctetString dataValue = null;
+    public BerEmbeddedPdv() {
+    }
+
+    public BerEmbeddedPdv(byte[] code) {
+        this.code = code;
+    }
+
+    public Identification getIdentification() {
+        return identification;
+    }
+
+    public void setIdentification(Identification identification) {
+        this.identification = identification;
+    }
+
+    public BerObjectDescriptor getDataValueDescriptor() {
+        return dataValueDescriptor;
+    }
+
+    public void setDataValueDescriptor(BerObjectDescriptor dataValueDescriptor) {
+        this.dataValueDescriptor = dataValueDescriptor;
+    }
+
+    public BerOctetString getDataValue() {
+        return dataValue;
+    }
+
+    public void setDataValue(BerOctetString dataValue) {
+        this.dataValue = dataValue;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        int sublength;
+
+        codeLength += dataValue.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        if (dataValueDescriptor != null) {
+            codeLength += dataValueDescriptor.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+            os.write(0x81);
+            codeLength += 1;
+        }
+
+        sublength = identification.encode(os);
+        codeLength += sublength;
+        codeLength += BerLength.encodeLength(os, sublength);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            subCodeLength += length.decode(is);
+            identification = new Identification();
+            subCodeLength += identification.decode(is, null);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            dataValueDescriptor = new BerObjectDescriptor();
+            subCodeLength += dataValueDescriptor.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            dataValue = new BerOctetString();
+            subCodeLength += dataValue.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: "
+                + subCodeLength);
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (identification != null) {
+            sb.append("identification: ");
+            identification.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("identification: <empty-required-field>");
+        }
+
+        if (dataValueDescriptor != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("dataValueDescriptor: ").append(dataValueDescriptor);
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (dataValue != null) {
+            sb.append("dataValue: ").append(dataValue);
+        } else {
+            sb.append("dataValue: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Identification implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        
+        @JsonIgnore public byte[] code = null;
+        private Syntaxes syntaxes = null;
+        private BerObjectIdentifier syntax = null;
+        private BerInteger presentationContextId = null;
+        private ContextNegotiation contextNegotiation = null;
+        private BerObjectIdentifier transferSyntax = null;
+        private BerNull fixed = null;
+        public Identification() {
+        }
+        public Identification(byte[] code) {
+            this.code = code;
+        }
+
+        public Syntaxes getSyntaxes() {
+            return syntaxes;
+        }
+
+        public void setSyntaxes(Syntaxes syntaxes) {
+            this.syntaxes = syntaxes;
+        }
+
+        public BerObjectIdentifier getSyntax() {
+            return syntax;
+        }
+
+        public void setSyntax(BerObjectIdentifier syntax) {
+            this.syntax = syntax;
+        }
+
+        public BerInteger getPresentationContextId() {
+            return presentationContextId;
+        }
+
+        public void setPresentationContextId(BerInteger presentationContextId) {
+            this.presentationContextId = presentationContextId;
+        }
+
+        public ContextNegotiation getContextNegotiation() {
+            return contextNegotiation;
+        }
+
+        public void setContextNegotiation(ContextNegotiation contextNegotiation) {
+            this.contextNegotiation = contextNegotiation;
+        }
+
+        public BerObjectIdentifier getTransferSyntax() {
+            return transferSyntax;
+        }
+
+        public void setTransferSyntax(BerObjectIdentifier transferSyntax) {
+            this.transferSyntax = transferSyntax;
+        }
+
+        public BerNull getFixed() {
+            return fixed;
+        }
+
+        public void setFixed(BerNull fixed) {
+            this.fixed = fixed;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            if (fixed != null) {
+                codeLength += fixed.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 5
+                os.write(0x85);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (transferSyntax != null) {
+                codeLength += transferSyntax.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 4
+                os.write(0x84);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (contextNegotiation != null) {
+                codeLength += contextNegotiation.encode(os, false);
+                // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+                os.write(0xA3);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (presentationContextId != null) {
+                codeLength += presentationContextId.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+                os.write(0x82);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (syntax != null) {
+                codeLength += syntax.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+                os.write(0x81);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            if (syntaxes != null) {
+                codeLength += syntaxes.encode(os, false);
+                // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+                os.write(0xA0);
+                codeLength += 1;
+                return codeLength;
+            }
+
+            throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, null);
+        }
+
+        public int decode(InputStream is, BerTag berTag) throws IOException {
+
+            int codeLength = 0;
+            BerTag passedTag = berTag;
+
+            if (berTag == null) {
+                berTag = new BerTag();
+                codeLength += berTag.decode(is);
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+                syntaxes = new Syntaxes();
+                codeLength += syntaxes.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+                syntax = new BerObjectIdentifier();
+                codeLength += syntax.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+                presentationContextId = new BerInteger();
+                codeLength += presentationContextId.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+                contextNegotiation = new ContextNegotiation();
+                codeLength += contextNegotiation.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
+                transferSyntax = new BerObjectIdentifier();
+                codeLength += transferSyntax.decode(is, false);
+                return codeLength;
+            }
+
+            if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
+                fixed = new BerNull();
+                codeLength += fixed.decode(is, false);
+                return codeLength;
+            }
+
+            if (passedTag != null) {
+                return 0;
+            }
+
+            throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os);
+            code = os.getArray();
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            if (syntaxes != null) {
+                sb.append("syntaxes: ");
+                syntaxes.appendAsString(sb, indentLevel + 1);
+                return;
+            }
+
+            if (syntax != null) {
+                sb.append("syntax: ").append(syntax);
+                return;
+            }
+
+            if (presentationContextId != null) {
+                sb.append("presentationContextId: ").append(presentationContextId);
+                return;
+            }
+
+            if (contextNegotiation != null) {
+                sb.append("contextNegotiation: ");
+                contextNegotiation.appendAsString(sb, indentLevel + 1);
+                return;
+            }
+
+            if (transferSyntax != null) {
+                sb.append("transferSyntax: ").append(transferSyntax);
+                return;
+            }
+
+            if (fixed != null) {
+                sb.append("fixed: ").append(fixed);
+                return;
+            }
+
+            sb.append("<none>");
+        }
+
+        public static class Syntaxes implements Serializable {
+
+            public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+            private static final long serialVersionUID = 1L;
+             @JsonIgnore public byte[] code = null;
+            private BerObjectIdentifier abstract_ = null;
+            private BerObjectIdentifier transfer = null;
+
+            public Syntaxes() {
+            }
+
+            public Syntaxes(byte[] code) {
+                this.code = code;
+            }
+
+            public BerObjectIdentifier getAbstract() {
+                return abstract_;
+            }
+
+            public void setAbstract(BerObjectIdentifier abstract_) {
+                this.abstract_ = abstract_;
+            }
+
+            public BerObjectIdentifier getTransfer() {
+                return transfer;
+            }
+
+            public void setTransfer(BerObjectIdentifier transfer) {
+                this.transfer = transfer;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+                return encode(os, true);
+            }
+
+            public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    if (withTag) {
+                        return tag.encode(os) + code.length;
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                codeLength += transfer.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+                os.write(0x81);
+                codeLength += 1;
+
+                codeLength += abstract_.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+                os.write(0x80);
+                codeLength += 1;
+
+                codeLength += BerLength.encodeLength(os, codeLength);
+
+                if (withTag) {
+                    codeLength += tag.encode(os);
+                }
+
+                return codeLength;
+
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, true);
+            }
+
+            public int decode(InputStream is, boolean withTag) throws IOException {
+                int codeLength = 0;
+                int subCodeLength = 0;
+                BerTag berTag = new BerTag();
+
+                if (withTag) {
+                    codeLength += tag.decodeAndCheck(is);
+                }
+
+                BerLength length = new BerLength();
+                codeLength += length.decode(is);
+
+                int totalLength = length.val;
+                codeLength += totalLength;
+
+                subCodeLength += berTag.decode(is);
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+                    abstract_ = new BerObjectIdentifier();
+                    subCodeLength += abstract_.decode(is, false);
+                    subCodeLength += berTag.decode(is);
+                } else {
+                    throw new IOException("Tag does not match the mandatory sequence element tag.");
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+                    transfer = new BerObjectIdentifier();
+                    subCodeLength += transfer.decode(is, false);
+                    if (subCodeLength == totalLength) {
+                        return codeLength;
+                    }
+                }
+                throw new IOException("Unexpected end of sequence, length tag: " + totalLength
+                        + ", actual sequence length: " + subCodeLength);
+
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os, false);
+                code = os.getArray();
+            }
+
+            @Override
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                sb.append("{");
+                sb.append("\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (abstract_ != null) {
+                    sb.append("abstract_: ").append(abstract_);
+                } else {
+                    sb.append("abstract_: <empty-required-field>");
+                }
+
+                sb.append(",\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (transfer != null) {
+                    sb.append("transfer: ").append(transfer);
+                } else {
+                    sb.append("transfer: <empty-required-field>");
+                }
+
+                sb.append("\n");
+                for (int i = 0; i < indentLevel; i++) {
+                    sb.append("\t");
+                }
+                sb.append("}");
+            }
+
+        }
+
+        public static class ContextNegotiation implements Serializable {
+
+            public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+            private static final long serialVersionUID = 1L;
+             @JsonIgnore public byte[] code = null;
+            private BerInteger presentationContextId = null;
+            private BerObjectIdentifier transferSyntax = null;
+
+            public ContextNegotiation() {
+            }
+
+            public ContextNegotiation(byte[] code) {
+                this.code = code;
+            }
+
+            public BerInteger getPresentationContextId() {
+                return presentationContextId;
+            }
+
+            public void setPresentationContextId(BerInteger presentationContextId) {
+                this.presentationContextId = presentationContextId;
+            }
+
+            public BerObjectIdentifier getTransferSyntax() {
+                return transferSyntax;
+            }
+
+            public void setTransferSyntax(BerObjectIdentifier transferSyntax) {
+                this.transferSyntax = transferSyntax;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+                return encode(os, true);
+            }
+
+            public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    if (withTag) {
+                        return tag.encode(os) + code.length;
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                codeLength += transferSyntax.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+                os.write(0x81);
+                codeLength += 1;
+
+                codeLength += presentationContextId.encode(os, false);
+                // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+                os.write(0x80);
+                codeLength += 1;
+
+                codeLength += BerLength.encodeLength(os, codeLength);
+
+                if (withTag) {
+                    codeLength += tag.encode(os);
+                }
+
+                return codeLength;
+
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, true);
+            }
+
+            public int decode(InputStream is, boolean withTag) throws IOException {
+                int codeLength = 0;
+                int subCodeLength = 0;
+                BerTag berTag = new BerTag();
+
+                if (withTag) {
+                    codeLength += tag.decodeAndCheck(is);
+                }
+
+                BerLength length = new BerLength();
+                codeLength += length.decode(is);
+
+                int totalLength = length.val;
+                codeLength += totalLength;
+
+                subCodeLength += berTag.decode(is);
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+                    presentationContextId = new BerInteger();
+                    subCodeLength += presentationContextId.decode(is, false);
+                    subCodeLength += berTag.decode(is);
+                } else {
+                    throw new IOException("Tag does not match the mandatory sequence element tag.");
+                }
+
+                if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+                    transferSyntax = new BerObjectIdentifier();
+                    subCodeLength += transferSyntax.decode(is, false);
+                    if (subCodeLength == totalLength) {
+                        return codeLength;
+                    }
+                }
+                throw new IOException("Unexpected end of sequence, length tag: " + totalLength
+                        + ", actual sequence length: " + subCodeLength);
+
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os, false);
+                code = os.getArray();
+            }
+
+            @Override
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                sb.append("{");
+                sb.append("\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (presentationContextId != null) {
+                    sb.append("presentationContextId: ").append(presentationContextId);
+                } else {
+                    sb.append("presentationContextId: <empty-required-field>");
+                }
+
+                sb.append(",\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (transferSyntax != null) {
+                    sb.append("transferSyntax: ").append(transferSyntax);
+                } else {
+                    sb.append("transferSyntax: <empty-required-field>");
+                }
+
+                sb.append("\n");
+                for (int i = 0; i < indentLevel; i++) {
+                    sb.append("\t");
+                }
+                sb.append("}");
+            }
+
+        }
+
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEnum.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEnum.java
new file mode 100644
index 0000000..8c5acaa
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerEnum.java
@@ -0,0 +1,59 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+
+public class BerEnum extends BerInteger {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.ENUMERATED_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerEnum() {
+    }
+
+    public BerEnum(byte[] code) {
+        this.code = code;
+    }
+
+    public BerEnum(BigInteger val) {
+        this.value = val;
+    }
+
+    public BerEnum(long val) {
+        this.value = BigInteger.valueOf(val);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerGeneralizedTime.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerGeneralizedTime.java
new file mode 100644
index 0000000..b4df6fc
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerGeneralizedTime.java
@@ -0,0 +1,133 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerVisibleString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class BerGeneralizedTime extends BerVisibleString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.GENERALIZED_TIME_TAG);
+    private static final long serialVersionUID = 1L;
+    /*
+     * Generalized time is one of the following (ITU-T X.680 08/2015): YYYYMMDDHH[MM[SS]][.fff] LocalTime
+     * YYYYMMDDHH[MM[SS]][.fff]Z UTC YYYYMMDDHH[MM[SS]][.fff]+-HH[MM] local time with time zone
+     *
+     * Regexp: ^ (?<year>\\d{4}) YYYY (?<month>\\d{2}) MM (?<day>\\d{2}) DD (?<hour>\\d{2}) HH ( [MM[SS]]
+     * (?<minute>\\d{2}) MM (?<second>\\d{2})? [SS] )? ([.,](?<frac>\\d+))? [.fff] (or [,fff]) (?<timezone> "" or "Z" or
+     * "+-HH[MM]" Z | ( "+-HH[MM]" [+-] "+-" \\d{2}(?<tzmin>\\d{2})? HH[MM] ) )? $
+     */
+    private final static String GENERALIZED_TIME_PATTERN = "^(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})(?<hour>\\d{2})((?<minute>\\d{2})(?<second>\\d{2})?)?([.,](?<frac>\\d+))?(?<timezone>Z|([+-]\\d{2}(?<tzmin>\\d{2})?))?$";
+    private final static Pattern generalizedTimePattern = Pattern.compile(GENERALIZED_TIME_PATTERN);
+
+    public BerGeneralizedTime() {
+    }
+
+    public BerGeneralizedTime(byte[] value) {
+        super(value);
+    }
+
+    public BerGeneralizedTime(String valueAsString) {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+    Calendar asCalendar() throws ParseException {
+
+        Matcher matcher = generalizedTimePattern.matcher(toString());
+
+        if (!matcher.find()) {
+            throw new ParseException("", 0);
+        }
+
+        String mg, mgf;
+        int year = Integer.valueOf(matcher.group("year"));
+        int month = Integer.valueOf(matcher.group("month"));
+        month -= 1; // java.util.Calendar's month goes from 0 to 11
+        int day = Integer.valueOf(matcher.group("day"));
+        int hour = Integer.valueOf(matcher.group("hour"));
+
+        mg = matcher.group("minute");
+        mgf = matcher.group("frac");
+        int minute = 0, second = 0, millisec = 0;
+        double frac = mgf == null ? 0 : Double.valueOf("0." + mgf);
+        if (mg == null) {
+            // Missing minutes and seconds
+            if (mgf != null) {
+                // frac is a fraction of a hour
+                millisec = (int) Math.round(1000 * 60 * 60 * frac);
+            }
+        } else {
+            minute = Integer.valueOf(mg);
+            mg = matcher.group("second");
+            if (mg == null) {
+                // Missing seconds
+                if (mgf != null) {
+                    // frac is a fraction of a minute
+                    millisec = (int) Math.round(1000 * 60 * frac);
+                }
+            } else {
+                second = Integer.valueOf(mg);
+                if (mgf != null) {
+                    // frac is a fraction of a second
+                    millisec = (int) Math.round(1000 * frac);
+                }
+            }
+        }
+
+        mg = matcher.group("timezone");
+        String mgt = matcher.group("tzmin");
+        String timeZoneStr = mg == null ? TimeZone.getDefault().getID()
+                : (mg.equals("Z") ? "UTC" : (mgt == null ? "GMT" + mg + "00" : "GMT" + mg));
+        TimeZone timeZone = TimeZone.getTimeZone(timeZoneStr);
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setLenient(true); // accept millisec greater than 999
+        calendar.set(year, month, day, hour, minute, second);
+        calendar.set(Calendar.MILLISECOND, millisec);
+        calendar.setTimeZone(timeZone);
+
+        return calendar;
+    }
+
+    Date asDate() throws ParseException {
+        return asCalendar().getTime();
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerInteger.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerInteger.java
new file mode 100644
index 0000000..0c80fbb
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerInteger.java
@@ -0,0 +1,128 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.math.BigInteger;
+
+public class BerInteger implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.INTEGER_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public BigInteger value;
+
+    public BerInteger() {
+    }
+
+    public BerInteger(byte[] code) {
+        this.code = code;
+    }
+
+    public BerInteger(BigInteger val) {
+        this.value = val;
+    }
+
+    public BerInteger(long val) {
+        this.value = BigInteger.valueOf(val);
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        byte[] encoded = value.toByteArray();
+        int codeLength = encoded.length;
+        os.write(encoded);
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        if (length.val < 1) {
+            throw new IOException("Decoded length of BerInteger is not correct");
+        }
+
+        byte[] byteCode = new byte[length.val];
+        Util.readFully(is, byteCode);
+
+        codeLength += length.val;
+
+        value = new BigInteger(byteCode);
+
+        return codeLength;
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    @JsonValue
+    @Override
+    public String toString() {
+        return "" + value;
+    }
+
+    public byte byteValue() {
+        return value.byteValue();
+    }
+
+    public short shortValue() {
+        return value.shortValue();
+    }
+
+    public int intValue() {
+        return value.intValue();
+    }
+
+    public long longValue() {
+        return value.longValue();
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerNull.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerNull.java
new file mode 100644
index 0000000..b342632
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerNull.java
@@ -0,0 +1,72 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerNull implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.NULL_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public BerNull() {
+    }
+
+    public BerNull(byte[] code) {
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = BerLength.encodeLength(os, 0);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        if (length.val != 0) {
+            throw new IOException("Decoded length of BerNull is not correct");
+        }
+
+        return codeLength;
+    }
+
+    
+    @Override
+    public String toString() {
+        return "ASN1_NULL";
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerObjectIdentifier.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerObjectIdentifier.java
new file mode 100644
index 0000000..b4f3e29
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerObjectIdentifier.java
@@ -0,0 +1,209 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BerObjectIdentifier implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.OBJECT_IDENTIFIER_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public int[] value;
+
+    public BerObjectIdentifier() {
+    }
+
+    public BerObjectIdentifier(byte[] code) {
+        this.code = code;
+    }
+
+    public BerObjectIdentifier(int[] value) {
+        if ((value.length < 2) || ((value[0] == 0 || value[0] == 1) && (value[1] > 39)) || value[0] > 2) {
+            throw new IllegalArgumentException("invalid object identifier components");
+        }
+        for (int objectIdentifierComponent : value) {
+            if (objectIdentifierComponent < 0) {
+                throw new IllegalArgumentException("invalid object identifier components");
+            }
+        }
+
+        this.value = value;
+
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int firstSubidentifier = 40 * value[0] + value[1];
+
+        int subidentifier;
+
+        int codeLength = 0;
+
+        for (int i = (value.length - 1); i > 0; i--) {
+
+            if (i == 1) {
+                subidentifier = firstSubidentifier;
+            } else {
+                subidentifier = value[i];
+            }
+
+            // get length of subidentifier
+            int subIDLength = 1;
+            while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) {
+                subIDLength++;
+            }
+
+            os.write(subidentifier & 0x7f);
+
+            for (int j = 1; j <= (subIDLength - 1); j++) {
+                os.write(((subidentifier >> (7 * j)) & 0xff) | 0x80);
+            }
+
+            codeLength += subIDLength;
+        }
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        if (length.val == 0) {
+            value = new int[0];
+            return codeLength;
+        }
+
+        byte[] byteCode = new byte[length.val];
+        Util.readFully(is, byteCode);
+
+        codeLength += length.val;
+
+        List<Integer> objectIdentifierComponentsList = new ArrayList<>();
+
+        int subIDEndIndex = 0;
+        while ((byteCode[subIDEndIndex] & 0x80) == 0x80) {
+            if (subIDEndIndex >= (length.val - 1)) {
+                throw new IOException("Invalid Object Identifier");
+            }
+            subIDEndIndex++;
+        }
+
+        int subidentifier = 0;
+        for (int i = 0; i <= subIDEndIndex; i++) {
+            subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7));
+        }
+
+        if (subidentifier < 40) {
+            objectIdentifierComponentsList.add(0);
+            objectIdentifierComponentsList.add(subidentifier);
+        } else if (subidentifier < 80) {
+            objectIdentifierComponentsList.add(1);
+            objectIdentifierComponentsList.add(subidentifier - 40);
+        } else {
+            objectIdentifierComponentsList.add(2);
+            objectIdentifierComponentsList.add(subidentifier - 80);
+        }
+
+        subIDEndIndex++;
+
+        while (subIDEndIndex < length.val) {
+            int subIDStartIndex = subIDEndIndex;
+
+            while ((byteCode[subIDEndIndex] & 0x80) == 0x80) {
+                if (subIDEndIndex == (length.val - 1)) {
+                    throw new IOException("Invalid Object Identifier");
+                }
+                subIDEndIndex++;
+            }
+            subidentifier = 0;
+            for (int j = subIDStartIndex; j <= subIDEndIndex; j++) {
+                subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7));
+            }
+            objectIdentifierComponentsList.add(subidentifier);
+            subIDEndIndex++;
+        }
+
+        value = new int[objectIdentifierComponentsList.size()];
+        for (int i = 0; i < objectIdentifierComponentsList.size(); i++) {
+            value[i] = objectIdentifierComponentsList.get(i);
+        }
+
+        return codeLength;
+
+    }
+
+    
+    @Override
+    public String toString() {
+        if (value == null || value.length == 0) {
+            return "";
+        }
+
+        String objIDString = "";
+        objIDString += value[0];
+        for (int i = 1; i < value.length; i++) {
+            objIDString += "." + value[i];
+        }
+        return objIDString;
+    }
+
+    public BerObjectIdentifier append(int value) {
+        if (this.value == null) {
+            return new BerObjectIdentifier(new int[]{value});
+        }
+        int[] values = new int[this.value.length + 1];
+        for (int i = 0; i < this.value.length; ++i) {
+            values[i] = this.value[i];
+        }
+        values[values.length - 1] = value;
+        return new BerObjectIdentifier(values);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerOctetString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerOctetString.java
new file mode 100644
index 0000000..16a085a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerOctetString.java
@@ -0,0 +1,80 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerOctetString implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.OCTET_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+    public byte[] value;
+
+    public BerOctetString() {
+    }
+
+    public BerOctetString(byte[] value) {
+        this.value = value;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        os.write(value);
+        int codeLength = value.length;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        value = new byte[length.val];
+
+        if (length.val != 0) {
+            Util.readFully(is, value);
+            codeLength += length.val;
+        }
+
+        return codeLength;
+
+    }
+
+    @JsonValue
+    @Override
+    public String toString() {
+        return DatatypeConverter.printHexBinary(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerReal.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerReal.java
new file mode 100644
index 0000000..2581e78
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerReal.java
@@ -0,0 +1,233 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.math.BigInteger;
+
+public class BerReal implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.REAL_TAG);
+    private static final long serialVersionUID = 1L;
+    
+    @JsonIgnore public byte[] code = null;
+
+    public double value;
+
+    public BerReal() {
+    }
+
+    public BerReal(byte[] code) {
+        this.code = code;
+    }
+
+    public BerReal(double value) {
+        this.value = value;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = encodeValue(os);
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    private int encodeValue(BerByteArrayOutputStream os) throws IOException {
+
+        // explained in Annex C and Ch. 8.5 of X.690
+
+        // we use binary encoding, with base 2 and F==0
+        // F is only needed when encoding with base 8 or 16
+
+        long longBits = Double.doubleToLongBits(value);
+
+        boolean isNegative = (longBits & 0x8000000000000000L) == 0x8000000000000000L;
+
+        int exponent = ((int) (longBits >> 52)) & 0x7ff;
+
+        long mantissa = (longBits & 0x000fffffffffffffL) | 0x0010000000000000L;
+
+        if (exponent == 0x7ff) {
+            if (mantissa == 0x0010000000000000L) {
+                if (isNegative) {
+                    // - infinity
+                    os.write(0x41);
+                } else {
+                    // + infinity
+                    os.write(0x40);
+                }
+                return 1;
+            } else {
+                throw new IOException("NAN not supported");
+            }
+        }
+
+        if ((exponent == 0 && mantissa == 0x0010000000000000L)) {
+            // zero
+            return 0;
+        }
+
+        // because IEEE double-precision format is (-1)^sign * 1.b51b50..b0 * 2^(e-1023) we need to subtract 1023 and 52
+        // from the exponent to get an exponent corresponding to an integer matissa as need here.
+        exponent -= 1075; // 1023 + 52 = 1075
+
+        // trailing zeros of the mantissa should be removed. Therefor find out how much the mantissa can be shifted and
+        // the exponent can be increased
+        int exponentIncr = 0;
+        while (((mantissa >> exponentIncr) & 0xff) == 0x00) {
+            exponentIncr += 8;
+        }
+        while (((mantissa >> exponentIncr) & 0x01) == 0x00) {
+            exponentIncr++;
+        }
+
+        exponent += exponentIncr;
+        mantissa >>= exponentIncr;
+
+        int mantissaLength = (Long.SIZE - Long.numberOfLeadingZeros(mantissa) + 7) / 8;
+
+        for (int i = 0; i < mantissaLength; i++) {
+            os.write((int) (mantissa >> (8 * i)));
+        }
+        int codeLength = mantissaLength;
+
+        byte[] exponentBytes = BigInteger.valueOf(exponent).toByteArray();
+        os.write(exponentBytes);
+        codeLength += exponentBytes.length;
+
+        byte exponentFormat = 0;
+        if (exponentBytes.length < 4) {
+            exponentFormat = (byte) (exponentBytes.length - 1);
+        } else {
+            os.write(exponentBytes.length);
+            codeLength++;
+            exponentFormat = 0x03;
+        }
+
+        if (isNegative) {
+            os.write(0x80 | 0x40 | exponentFormat);
+        } else {
+            os.write(0x80 | exponentFormat);
+        }
+
+        codeLength++;
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        if (length.val == 0) {
+            value = 0;
+            return codeLength;
+        }
+
+        if (length.val == 1) {
+            int nextByte = is.read();
+            if (nextByte == -1) {
+                throw new EOFException("Unexpected end of input stream.");
+            }
+            if (nextByte == 0x40) {
+                value = Double.POSITIVE_INFINITY;
+            } else if (nextByte == 0x41) {
+                value = Double.NEGATIVE_INFINITY;
+            } else {
+                throw new IOException("invalid real encoding");
+            }
+            return codeLength + 1;
+        }
+
+        byte[] byteCode = new byte[length.val];
+        Util.readFully(is, byteCode);
+
+        if ((byteCode[0] & 0x80) != 0x80) {
+            throw new IOException("Only binary REAL encoding is supported");
+        }
+
+        codeLength += length.val;
+        int tempLength = 1;
+
+        int sign = 1;
+        if ((byteCode[0] & 0x40) == 0x40) {
+            sign = -1;
+        }
+
+        int exponentLength = (byteCode[0] & 0x03) + 1;
+        if (exponentLength == 4) {
+            exponentLength = byteCode[1];
+            tempLength++;
+        }
+
+        tempLength += exponentLength;
+
+        int exponent = 0;
+        for (int i = 0; i < exponentLength; i++) {
+            exponent |= byteCode[1 + i] << (8 * (exponentLength - i - 1));
+        }
+
+        long mantissa = 0;
+        for (int i = 0; i < length.val - tempLength; i++) {
+            mantissa |= (byteCode[i + tempLength] & 0xffL) << (8 * (length.val - tempLength - i - 1));
+        }
+
+        value = sign * mantissa * Math.pow(2, exponent);
+
+        return codeLength;
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    
+    @Override
+    public String toString() {
+        return "" + value;
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTime.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTime.java
new file mode 100644
index 0000000..6dad2af
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTime.java
@@ -0,0 +1,56 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerVisibleString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerTime extends BerVisibleString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.TIME_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerTime() {
+    }
+
+    public BerTime(byte[] value) {
+        super(value);
+    }
+
+    public BerTime(String valueAsString) throws UnsupportedEncodingException {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTimeOfDay.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTimeOfDay.java
new file mode 100644
index 0000000..2507525
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerTimeOfDay.java
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerTimeOfDay extends BerTime {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.TIME_OF_DAY_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerTimeOfDay() {
+    }
+
+    public BerTimeOfDay(byte[] value) {
+        super(value);
+    }
+
+    public BerTimeOfDay(String valueAsString) throws UnsupportedEncodingException {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerUtcTime.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerUtcTime.java
new file mode 100644
index 0000000..e292aa5
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/BerUtcTime.java
@@ -0,0 +1,107 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerVisibleString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class BerUtcTime extends BerVisibleString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.UTC_TIME_TAG);
+    private static final long serialVersionUID = 1L;
+    /*
+     * UTC time is one of the following (ITU-T X.680 08/2015): YYMMDDhhmm[ss]Z YYMMDDhhmm[ss](+|-)hhmm Regexp: ^
+     * (?<year>\\d{2}) YY (?<month>\\d{2}) MM (?<day>\\d{2}) DD (?<hour>\\d{2}) hh (?<minute>\\d{2}) mm
+     * (?<second>\\d{2})? ss (?<timezone> Z | Z or (+|-)hhmm ( [+-]\\d{4} (+|-)hhmm ) ) $
+     */
+    private final static String UTC_TIME_PATTERN = "^(?<year>\\d{2})(?<month>\\d{2})(?<day>\\d{2})(?<hour>\\d{2})(?<minute>\\d{2})(?<second>\\d{2})?(?<timezone>Z|([+-]\\d{4}))$";
+    private final static Pattern utcTimePattern = Pattern.compile(UTC_TIME_PATTERN);
+
+    public BerUtcTime() {
+    }
+
+    public BerUtcTime(byte[] value) {
+        this.value = value;
+    }
+
+    public BerUtcTime(String valueAsString) {
+        super(valueAsString);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+    @SuppressWarnings("WeakerAccess")
+    Calendar asCalendar() throws ParseException {
+
+        Matcher matcher = utcTimePattern.matcher(toString());
+
+        if (!matcher.find())
+            throw new ParseException("", 0);
+
+        String mg;
+        int year = Integer.valueOf(matcher.group("year"));
+        int month = Integer.valueOf(matcher.group("month"));
+        month -= 1; // java.util.Calendar's month goes from 0 to 11
+        int day = Integer.valueOf(matcher.group("day"));
+        int hour = Integer.valueOf(matcher.group("hour"));
+        int minute = Integer.valueOf(matcher.group("minute"));
+        mg = matcher.group("second");
+        int second = mg == null ? 0 : Integer.valueOf(mg);
+
+        mg = matcher.group("timezone");
+        String timeZoneStr = mg.equals("Z") ? "UTC" : "GMT" + mg;
+        TimeZone timeZone = TimeZone.getTimeZone(timeZoneStr);
+
+        Calendar calendar = Calendar.getInstance(timeZone);
+
+        // Add 2000 to the year
+        int century = (calendar.get(Calendar.YEAR) / 100) * 100;
+        year += century;
+
+        // noinspection MagicConstant
+        calendar.set(year, month, day, hour, minute, second);
+        calendar.set(Calendar.MILLISECOND, 0);
+
+        return calendar;
+    }
+
+    Date asDate() throws ParseException {
+        return asCalendar().getTime();
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerBMPString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerBMPString.java
new file mode 100644
index 0000000..682fafa
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerBMPString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerBMPString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.BMP_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerBMPString() {
+    }
+
+    public BerBMPString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGeneralString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGeneralString.java
new file mode 100644
index 0000000..0608d43
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGeneralString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerGeneralString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.GENERAL_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerGeneralString() {
+    }
+
+    public BerGeneralString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGraphicString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGraphicString.java
new file mode 100644
index 0000000..1efedb6
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerGraphicString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerGraphicString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.GRAPHIC_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerGraphicString() {
+    }
+
+    public BerGraphicString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerIA5String.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerIA5String.java
new file mode 100644
index 0000000..e38f3df
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerIA5String.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerIA5String extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.IA5_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerIA5String() {
+    }
+
+    public BerIA5String(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerNumericString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerNumericString.java
new file mode 100644
index 0000000..141f3ed
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerNumericString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerNumericString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.NUMERIC_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerNumericString() {
+    }
+
+    public BerNumericString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerObjectDescriptor.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerObjectDescriptor.java
new file mode 100644
index 0000000..bcf4829
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerObjectDescriptor.java
@@ -0,0 +1,51 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerObjectDescriptor extends BerGraphicString {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.OBJECT_DESCRIPTOR_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerObjectDescriptor() {
+    }
+
+    public BerObjectDescriptor(byte[] value) {
+        super(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength;
+
+        codeLength = super.encode(os, false);
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerPrintableString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerPrintableString.java
new file mode 100644
index 0000000..e6313bf
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerPrintableString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerPrintableString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.PRINTABLE_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerPrintableString() {
+    }
+
+    public BerPrintableString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerTeletexString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerTeletexString.java
new file mode 100644
index 0000000..ca56059
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerTeletexString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerTeletexString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.TELETEX_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerTeletexString() {
+    }
+
+    public BerTeletexString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUTF8String.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUTF8String.java
new file mode 100644
index 0000000..b27b82c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUTF8String.java
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+public class BerUTF8String extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.UTF8_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerUTF8String() {
+    }
+
+    public BerUTF8String(byte[] value) {
+        this.value = value;
+    }
+
+    public BerUTF8String(String valueAsString) throws UnsupportedEncodingException {
+        value = valueAsString.getBytes("UTF-8");
+    }
+
+    
+    @Override
+    public String toString() {
+        try {
+            return new String(value, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            return "Unsupported Encoding";
+        }
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUniversalString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUniversalString.java
new file mode 100644
index 0000000..41e0a89
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerUniversalString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerUniversalString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.UNIVERSAL_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerUniversalString() {
+    }
+
+    public BerUniversalString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVideotexString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVideotexString.java
new file mode 100644
index 0000000..5d88179
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVideotexString.java
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerOctetString;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BerVideotexString extends BerOctetString {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.VIDEOTEX_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+
+    public BerVideotexString() {
+    }
+
+    public BerVideotexString(byte[] value) {
+        this.value = value;
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+    @Override
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        int codeLength = super.encode(os, false);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    @Override
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        codeLength += super.decode(is, false);
+
+        return codeLength;
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVisibleString.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVisibleString.java
new file mode 100644
index 0000000..14a8665
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/ber/types/string/BerVisibleString.java
@@ -0,0 +1,83 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.onosproject.xran.asn1lib.ber.types.string;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.internal.Util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BerVisibleString implements Serializable {
+
+    public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.VISIBLE_STRING_TAG);
+    private static final long serialVersionUID = 1L;
+    public byte[] value;
+
+    public BerVisibleString() {
+    }
+
+    public BerVisibleString(byte[] value) {
+        this.value = value;
+    }
+
+    public BerVisibleString(String valueAsString) {
+        value = valueAsString.getBytes();
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        os.write(value);
+        int codeLength = value.length;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+
+        int codeLength = 0;
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        value = new byte[length.val];
+
+        if (length.val != 0) {
+            Util.readFully(is, value);
+            codeLength += length.val;
+        }
+
+        return codeLength;
+
+    }
+
+    
+    @Override
+    public String toString() {
+        return new String(value);
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/package-info.java
new file mode 100644
index 0000000..17384cd
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/package-info.java
@@ -0,0 +1 @@
+package org.onosproject.xran.asn1lib;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionRequest.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionRequest.java
new file mode 100644
index 0000000..3f31a27
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionRequest.java
@@ -0,0 +1,272 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ERABParams;
+import org.onosproject.xran.asn1lib.api.UEAMBR;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BearerAdmissionRequest implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private UEAMBR ueAmbr = null;
+    private BerInteger numErabs = null;
+    private ERABParams erabParams = null;
+
+    public BearerAdmissionRequest() {
+    }
+
+    public BearerAdmissionRequest(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public UEAMBR getUeAmbr() {
+        return ueAmbr;
+    }
+
+    public void setUeAmbr(UEAMBR ueAmbr) {
+        this.ueAmbr = ueAmbr;
+    }
+
+    public BerInteger getNumErabs() {
+        return numErabs;
+    }
+
+    public void setNumErabs(BerInteger numErabs) {
+        this.numErabs = numErabs;
+    }
+
+    public ERABParams getErabParams() {
+        return erabParams;
+    }
+
+    public void setErabParams(ERABParams erabParams) {
+        this.erabParams = erabParams;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += erabParams.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += numErabs.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += ueAmbr.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            ueAmbr = new UEAMBR();
+            subCodeLength += ueAmbr.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            numErabs = new BerInteger();
+            subCodeLength += numErabs.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            erabParams = new ERABParams();
+            subCodeLength += erabParams.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ueAmbr != null) {
+            sb.append("ueAmbr: ");
+            ueAmbr.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ueAmbr: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numErabs != null) {
+            sb.append("numErabs: ").append(numErabs);
+        } else {
+            sb.append("numErabs: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (erabParams != null) {
+            sb.append("erabParams: ");
+            erabParams.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("erabParams: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionResponse.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionResponse.java
new file mode 100644
index 0000000..333aca1
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionResponse.java
@@ -0,0 +1,281 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.*;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+
+public class BearerAdmissionResponse implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private BerInteger numErabList = null;
+    private ERABResponse erabResponse = null;
+
+    public BearerAdmissionResponse() {
+    }
+
+    public BearerAdmissionResponse(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, ERABParams erabParams, BerInteger numParams, boolean b) {
+        ERABResponse erabResponse = new ERABResponse();
+
+        for (int i = 0; i < numParams.intValue(); i++) {
+            ERABParamsItem erabParamsItem = erabParams.getERABParamsItem().get(i);
+
+            ERABResponseItem responseItem = new ERABResponseItem();
+            responseItem.setId(erabParamsItem.getId());
+
+            // FIXME: add logic
+            responseItem.setDecision(new ERABDecision(b ? 0 : 1));
+
+            erabResponse.getERABResponseItem().add(responseItem);
+        }
+
+
+        BearerAdmissionResponse bearerAdmissionResponse = new BearerAdmissionResponse();
+        bearerAdmissionResponse.setCrnti(crnti);
+        bearerAdmissionResponse.setEcgi(ecgi);
+        bearerAdmissionResponse.setErabResponse(erabResponse);
+        bearerAdmissionResponse.setNumErabList(numParams);
+
+        XrancPduBody body = new XrancPduBody();
+        body.setBearerAdmissionResponse(bearerAdmissionResponse);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        XrancApiID apiID = new XrancApiID(9);
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setHdr(hdr);
+        pdu.setBody(body);
+
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public BerInteger getNumErabList() {
+        return numErabList;
+    }
+
+    public void setNumErabList(BerInteger numErabList) {
+        this.numErabList = numErabList;
+    }
+
+    public ERABResponse getErabResponse() {
+        return erabResponse;
+    }
+
+    public void setErabResponse(ERABResponse erabResponse) {
+        this.erabResponse = erabResponse;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += erabResponse.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += numErabList.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            numErabList = new BerInteger();
+            subCodeLength += numErabList.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            erabResponse = new ERABResponse();
+            subCodeLength += erabResponse.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numErabList != null) {
+            sb.append("numErabList: ").append(numErabList);
+        } else {
+            sb.append("numErabList: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (erabResponse != null) {
+            sb.append("erabResponse: ");
+            erabResponse.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("erabResponse: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionStatus.java
new file mode 100644
index 0000000..aa5fdea
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerAdmissionStatus.java
@@ -0,0 +1,238 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ERABResponse;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class BearerAdmissionStatus implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private BerInteger numErabs = null;
+    private ERABResponse erabStatus = null;
+
+    public BearerAdmissionStatus() {
+    }
+
+    public BearerAdmissionStatus(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public BerInteger getNumErabs() {
+        return numErabs;
+    }
+
+    public void setNumErabs(BerInteger numErabs) {
+        this.numErabs = numErabs;
+    }
+
+    public ERABResponse getErabStatus() {
+        return erabStatus;
+    }
+
+    public void setErabStatus(ERABResponse erabStatus) {
+        this.erabStatus = erabStatus;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += erabStatus.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += numErabs.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            numErabs = new BerInteger();
+            subCodeLength += numErabs.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            erabStatus = new ERABResponse();
+            subCodeLength += erabStatus.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numErabs != null) {
+            sb.append("numErabs: ").append(numErabs);
+        } else {
+            sb.append("numErabs: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (erabStatus != null) {
+            sb.append("erabStatus: ");
+            erabStatus.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("erabStatus: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerReleaseInd.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerReleaseInd.java
new file mode 100644
index 0000000..7b4e15c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/BearerReleaseInd.java
@@ -0,0 +1,369 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ERABID;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class BearerReleaseInd implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private BerInteger numErabs = null;
+    private ErabIds erabIds = null;
+    public BearerReleaseInd() {
+    }
+
+    public BearerReleaseInd(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public BerInteger getNumErabs() {
+        return numErabs;
+    }
+
+    public void setNumErabs(BerInteger numErabs) {
+        this.numErabs = numErabs;
+    }
+
+    public ErabIds getErabIds() {
+        return erabIds;
+    }
+
+    public void setErabIds(ErabIds erabIds) {
+        this.erabIds = erabIds;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += erabIds.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += numErabs.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            numErabs = new BerInteger();
+            subCodeLength += numErabs.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            erabIds = new ErabIds();
+            subCodeLength += erabIds.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numErabs != null) {
+            sb.append("numErabs: ").append(numErabs);
+        } else {
+            sb.append("numErabs: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (erabIds != null) {
+            sb.append("erabIds: ");
+            erabIds.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("erabIds: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class ErabIds implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<ERABID> seqOf = null;
+
+        public ErabIds() {
+            seqOf = new ArrayList<ERABID>();
+        }
+
+        public ErabIds(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<ERABID> getERABID() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<ERABID>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                ERABID element = new ERABID();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<ERABID> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigReport.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigReport.java
new file mode 100644
index 0000000..896461a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigReport.java
@@ -0,0 +1,783 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.*;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class CellConfigReport implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private PhysCellId pci = null;
+    private CandScells candScells = null;
+    private ARFCNValue earfcnDl = null;
+    private ARFCNValue earfcnUl = null;
+    private BerInteger rbsPerTtiDl = null;
+    private BerInteger rbsPerTtiUl = null;
+    private BerInteger numTxAntenna = null;
+    private DuplexMode duplexMode = null;
+    private BerInteger tddConfig = null;
+    private BerInteger tddSplSfConfig = null;
+    private BerInteger maxNumConnectedUes = null;
+    private BerInteger maxNumConnectedBearers = null;
+    private BerInteger maxNumUesSchedPerTtiDl = null;
+    private BerInteger maxNumUesSchedPerTtiUl = null;
+    private BerBoolean dlfsSchedEnable = null;
+    private BerBitString featureSupportList = null;
+    public CellConfigReport() {
+    }
+
+    public CellConfigReport(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public PhysCellId getPci() {
+        return pci;
+    }
+
+    public void setPci(PhysCellId pci) {
+        this.pci = pci;
+    }
+
+    public CandScells getCandScells() {
+        return candScells;
+    }
+
+    public void setCandScells(CandScells candScells) {
+        this.candScells = candScells;
+    }
+
+    public ARFCNValue getEarfcnDl() {
+        return earfcnDl;
+    }
+
+    public void setEarfcnDl(ARFCNValue earfcnDl) {
+        this.earfcnDl = earfcnDl;
+    }
+
+    public ARFCNValue getEarfcnUl() {
+        return earfcnUl;
+    }
+
+    public void setEarfcnUl(ARFCNValue earfcnUl) {
+        this.earfcnUl = earfcnUl;
+    }
+
+    public BerInteger getRbsPerTtiDl() {
+        return rbsPerTtiDl;
+    }
+
+    public void setRbsPerTtiDl(BerInteger rbsPerTtiDl) {
+        this.rbsPerTtiDl = rbsPerTtiDl;
+    }
+
+    public BerInteger getRbsPerTtiUl() {
+        return rbsPerTtiUl;
+    }
+
+    public void setRbsPerTtiUl(BerInteger rbsPerTtiUl) {
+        this.rbsPerTtiUl = rbsPerTtiUl;
+    }
+
+    public BerInteger getNumTxAntenna() {
+        return numTxAntenna;
+    }
+
+    public void setNumTxAntenna(BerInteger numTxAntenna) {
+        this.numTxAntenna = numTxAntenna;
+    }
+
+    public DuplexMode getDuplexMode() {
+        return duplexMode;
+    }
+
+    public void setDuplexMode(DuplexMode duplexMode) {
+        this.duplexMode = duplexMode;
+    }
+
+    public BerInteger getTddConfig() {
+        return tddConfig;
+    }
+
+    public void setTddConfig(BerInteger tddConfig) {
+        this.tddConfig = tddConfig;
+    }
+
+    public BerInteger getTddSplSfConfig() {
+        return tddSplSfConfig;
+    }
+
+    public void setTddSplSfConfig(BerInteger tddSplSfConfig) {
+        this.tddSplSfConfig = tddSplSfConfig;
+    }
+
+    public BerInteger getMaxNumConnectedUes() {
+        return maxNumConnectedUes;
+    }
+
+    public void setMaxNumConnectedUes(BerInteger maxNumConnectedUes) {
+        this.maxNumConnectedUes = maxNumConnectedUes;
+    }
+
+    public BerInteger getMaxNumConnectedBearers() {
+        return maxNumConnectedBearers;
+    }
+
+    public void setMaxNumConnectedBearers(BerInteger maxNumConnectedBearers) {
+        this.maxNumConnectedBearers = maxNumConnectedBearers;
+    }
+
+    public BerInteger getMaxNumUesSchedPerTtiDl() {
+        return maxNumUesSchedPerTtiDl;
+    }
+
+    public void setMaxNumUesSchedPerTtiDl(BerInteger maxNumUesSchedPerTtiDl) {
+        this.maxNumUesSchedPerTtiDl = maxNumUesSchedPerTtiDl;
+    }
+
+    public BerInteger getMaxNumUesSchedPerTtiUl() {
+        return maxNumUesSchedPerTtiUl;
+    }
+
+    public void setMaxNumUesSchedPerTtiUl(BerInteger maxNumUesSchedPerTtiUl) {
+        this.maxNumUesSchedPerTtiUl = maxNumUesSchedPerTtiUl;
+    }
+
+    public BerBoolean getDlfsSchedEnable() {
+        return dlfsSchedEnable;
+    }
+
+    public void setDlfsSchedEnable(BerBoolean dlfsSchedEnable) {
+        this.dlfsSchedEnable = dlfsSchedEnable;
+    }
+
+    public BerBitString getFeatureSupportList() {
+        return featureSupportList;
+    }
+
+    public void setFeatureSupportList(BerBitString featureSupportList) {
+        this.featureSupportList = featureSupportList;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (featureSupportList != null) {
+            codeLength += featureSupportList.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 16
+            os.write(0x90);
+            codeLength += 1;
+        }
+
+        codeLength += dlfsSchedEnable.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 15
+        os.write(0x8F);
+        codeLength += 1;
+
+        codeLength += maxNumUesSchedPerTtiUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 14
+        os.write(0x8E);
+        codeLength += 1;
+
+        codeLength += maxNumUesSchedPerTtiDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 13
+        os.write(0x8D);
+        codeLength += 1;
+
+        codeLength += maxNumConnectedBearers.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 12
+        os.write(0x8C);
+        codeLength += 1;
+
+        codeLength += maxNumConnectedUes.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 11
+        os.write(0x8B);
+        codeLength += 1;
+
+        if (tddSplSfConfig != null) {
+            codeLength += tddSplSfConfig.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 10
+            os.write(0x8A);
+            codeLength += 1;
+        }
+
+        if (tddConfig != null) {
+            codeLength += tddConfig.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 9
+            os.write(0x89);
+            codeLength += 1;
+        }
+
+        codeLength += duplexMode.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 8
+        os.write(0x88);
+        codeLength += 1;
+
+        codeLength += numTxAntenna.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 7
+        os.write(0x87);
+        codeLength += 1;
+
+        codeLength += rbsPerTtiUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 6
+        os.write(0x86);
+        codeLength += 1;
+
+        codeLength += rbsPerTtiDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 5
+        os.write(0x85);
+        codeLength += 1;
+
+        codeLength += earfcnUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 4
+        os.write(0x84);
+        codeLength += 1;
+
+        codeLength += earfcnDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += candScells.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += pci.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            pci = new PhysCellId();
+            subCodeLength += pci.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            candScells = new CandScells();
+            subCodeLength += candScells.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            earfcnDl = new ARFCNValue();
+            subCodeLength += earfcnDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
+            earfcnUl = new ARFCNValue();
+            subCodeLength += earfcnUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
+            rbsPerTtiDl = new BerInteger();
+            subCodeLength += rbsPerTtiDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
+            rbsPerTtiUl = new BerInteger();
+            subCodeLength += rbsPerTtiUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
+            numTxAntenna = new BerInteger();
+            subCodeLength += numTxAntenna.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
+            duplexMode = new DuplexMode();
+            subCodeLength += duplexMode.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
+            tddConfig = new BerInteger();
+            subCodeLength += tddConfig.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) {
+            tddSplSfConfig = new BerInteger();
+            subCodeLength += tddSplSfConfig.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
+            maxNumConnectedUes = new BerInteger();
+            subCodeLength += maxNumConnectedUes.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) {
+            maxNumConnectedBearers = new BerInteger();
+            subCodeLength += maxNumConnectedBearers.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 13)) {
+            maxNumUesSchedPerTtiDl = new BerInteger();
+            subCodeLength += maxNumUesSchedPerTtiDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 14)) {
+            maxNumUesSchedPerTtiUl = new BerInteger();
+            subCodeLength += maxNumUesSchedPerTtiUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 15)) {
+            dlfsSchedEnable = new BerBoolean();
+            subCodeLength += dlfsSchedEnable.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 16)) {
+            featureSupportList = new BerBitString();
+            subCodeLength += featureSupportList.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pci != null) {
+            sb.append("pci: ").append(pci);
+        } else {
+            sb.append("pci: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (candScells != null) {
+            sb.append("candScells: ");
+            candScells.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("candScells: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (earfcnDl != null) {
+            sb.append("earfcnDl: ").append(earfcnDl);
+        } else {
+            sb.append("earfcnDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (earfcnUl != null) {
+            sb.append("earfcnUl: ").append(earfcnUl);
+        } else {
+            sb.append("earfcnUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (rbsPerTtiDl != null) {
+            sb.append("rbsPerTtiDl: ").append(rbsPerTtiDl);
+        } else {
+            sb.append("rbsPerTtiDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (rbsPerTtiUl != null) {
+            sb.append("rbsPerTtiUl: ").append(rbsPerTtiUl);
+        } else {
+            sb.append("rbsPerTtiUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (numTxAntenna != null) {
+            sb.append("numTxAntenna: ").append(numTxAntenna);
+        } else {
+            sb.append("numTxAntenna: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (duplexMode != null) {
+            sb.append("duplexMode: ").append(duplexMode);
+        } else {
+            sb.append("duplexMode: <empty-required-field>");
+        }
+
+        if (tddConfig != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("tddConfig: ").append(tddConfig);
+        }
+
+        if (tddSplSfConfig != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("tddSplSfConfig: ").append(tddSplSfConfig);
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (maxNumConnectedUes != null) {
+            sb.append("maxNumConnectedUes: ").append(maxNumConnectedUes);
+        } else {
+            sb.append("maxNumConnectedUes: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (maxNumConnectedBearers != null) {
+            sb.append("maxNumConnectedBearers: ").append(maxNumConnectedBearers);
+        } else {
+            sb.append("maxNumConnectedBearers: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (maxNumUesSchedPerTtiDl != null) {
+            sb.append("maxNumUesSchedPerTtiDl: ").append(maxNumUesSchedPerTtiDl);
+        } else {
+            sb.append("maxNumUesSchedPerTtiDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (maxNumUesSchedPerTtiUl != null) {
+            sb.append("maxNumUesSchedPerTtiUl: ").append(maxNumUesSchedPerTtiUl);
+        } else {
+            sb.append("maxNumUesSchedPerTtiUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (dlfsSchedEnable != null) {
+            sb.append("dlfsSchedEnable: ").append(dlfsSchedEnable);
+        } else {
+            sb.append("dlfsSchedEnable: <empty-required-field>");
+        }
+
+        if (featureSupportList != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("featureSupportList: ").append(featureSupportList);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class CandScells implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CandScell> seqOf = null;
+
+        public CandScells() {
+            seqOf = new ArrayList<CandScell>();
+        }
+
+        public CandScells(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<CandScell> getCandScell() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CandScell>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CandScell element = new CandScell();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CandScell> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigRequest.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigRequest.java
new file mode 100644
index 0000000..7de2dd1
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/CellConfigRequest.java
@@ -0,0 +1,163 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class CellConfigRequest implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+
+    public CellConfigRequest() {
+    }
+
+    public CellConfigRequest(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi) {
+        CellConfigRequest cellConfigRequest = new CellConfigRequest();
+        cellConfigRequest.setEcgi(ecgi);
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (Exception ignored) {
+        }
+
+        XrancApiID apiID = new XrancApiID(0);
+        XrancPduBody body = new XrancPduBody();
+        body.setCellConfigRequest(cellConfigRequest);
+
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setBody(body);
+        pdu.setHdr(hdr);
+
+        return pdu;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOCause.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOCause.java
new file mode 100644
index 0000000..140b234
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOCause.java
@@ -0,0 +1,402 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.RXSigReport;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class HOCause implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgiS = null;
+    private ECGI ecgiT = null;
+    private BerBitString hoCause = null;
+    private HoTrigger hoTrigger = null;
+    public HOCause() {
+    }
+
+    public HOCause(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgiS() {
+        return ecgiS;
+    }
+
+    public void setEcgiS(ECGI ecgiS) {
+        this.ecgiS = ecgiS;
+    }
+
+    public ECGI getEcgiT() {
+        return ecgiT;
+    }
+
+    public void setEcgiT(ECGI ecgiT) {
+        this.ecgiT = ecgiT;
+    }
+
+    public BerBitString getHoCause() {
+        return hoCause;
+    }
+
+    public void setHoCause(BerBitString hoCause) {
+        this.hoCause = hoCause;
+    }
+
+    public HoTrigger getHoTrigger() {
+        return hoTrigger;
+    }
+
+    public void setHoTrigger(HoTrigger hoTrigger) {
+        this.hoTrigger = hoTrigger;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += hoTrigger.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += hoCause.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += ecgiT.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgiS.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgiS = new ECGI();
+            subCodeLength += ecgiS.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            ecgiT = new ECGI();
+            subCodeLength += ecgiT.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            hoCause = new BerBitString();
+            subCodeLength += hoCause.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            hoTrigger = new HoTrigger();
+            subCodeLength += hoTrigger.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiS != null) {
+            sb.append("ecgiS: ");
+            ecgiS.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiS: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiT != null) {
+            sb.append("ecgiT: ");
+            ecgiT.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiT: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (hoCause != null) {
+            sb.append("hoCause: ").append(hoCause);
+        } else {
+            sb.append("hoCause: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (hoTrigger != null) {
+            sb.append("hoTrigger: ");
+            hoTrigger.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("hoTrigger: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class HoTrigger implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<RXSigReport> seqOf = null;
+
+        public HoTrigger() {
+            seqOf = new ArrayList<RXSigReport>();
+        }
+
+        public HoTrigger(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<RXSigReport> getRXSigReport() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<RXSigReport>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                RXSigReport element = new RXSigReport();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<RXSigReport> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOComplete.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOComplete.java
new file mode 100644
index 0000000..8094bab
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOComplete.java
@@ -0,0 +1,205 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class HOComplete implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgiT = null;
+    private ECGI ecgiS = null;
+    private CRNTI crntiNew = null;
+
+    public HOComplete() {
+    }
+
+    public HOComplete(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgiT() {
+        return ecgiT;
+    }
+
+    public void setEcgiT(ECGI ecgiT) {
+        this.ecgiT = ecgiT;
+    }
+
+    public ECGI getEcgiS() {
+        return ecgiS;
+    }
+
+    public void setEcgiS(ECGI ecgiS) {
+        this.ecgiS = ecgiS;
+    }
+
+    public CRNTI getCrntiNew() {
+        return crntiNew;
+    }
+
+    public void setCrntiNew(CRNTI crntiNew) {
+        this.crntiNew = crntiNew;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += crntiNew.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgiS.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += ecgiT.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgiT = new ECGI();
+            subCodeLength += ecgiT.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgiS = new ECGI();
+            subCodeLength += ecgiS.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            crntiNew = new CRNTI();
+            subCodeLength += crntiNew.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiT != null) {
+            sb.append("ecgiT: ");
+            ecgiT.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiT: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiS != null) {
+            sb.append("ecgiS: ");
+            ecgiS.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiS: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crntiNew != null) {
+            sb.append("crntiNew: ").append(crntiNew);
+        } else {
+            sb.append("crntiNew: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOFailure.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOFailure.java
new file mode 100644
index 0000000..9b96818
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HOFailure.java
@@ -0,0 +1,205 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.HOFailureCause;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class HOFailure implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private HOFailureCause cause = null;
+
+    public HOFailure() {
+    }
+
+    public HOFailure(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public HOFailureCause getCause() {
+        return cause;
+    }
+
+    public void setCause(HOFailureCause cause) {
+        this.cause = cause;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += cause.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            cause = new HOFailureCause();
+            subCodeLength += cause.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (cause != null) {
+            sb.append("cause: ").append(cause);
+        } else {
+            sb.append("cause: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HORequest.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HORequest.java
new file mode 100644
index 0000000..2618f0b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/HORequest.java
@@ -0,0 +1,234 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class HORequest implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgiS = null;
+    private ECGI ecgiT = null;
+
+    public HORequest() {
+    }
+
+    public HORequest(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(CRNTI crnti, ECGI ecgis, ECGI ecgit) {
+        HORequest hoRequest = new HORequest();
+
+        hoRequest.setCrnti(crnti);
+        hoRequest.setEcgiS(ecgis);
+        hoRequest.setEcgiT(ecgit);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (Exception ignored) {
+        }
+
+        XrancApiID apiID = new XrancApiID(12);
+        XrancPduBody body = new XrancPduBody();
+        body.setHORequest(hoRequest);
+
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setBody(body);
+        pdu.setHdr(hdr);
+
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgiS() {
+        return ecgiS;
+    }
+
+    public void setEcgiS(ECGI ecgiS) {
+        this.ecgiS = ecgiS;
+    }
+
+    public ECGI getEcgiT() {
+        return ecgiT;
+    }
+
+    public void setEcgiT(ECGI ecgiT) {
+        this.ecgiT = ecgiT;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += ecgiT.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgiS.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgiS = new ECGI();
+            subCodeLength += ecgiS.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            ecgiT = new ECGI();
+            subCodeLength += ecgiT.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiS != null) {
+            sb.append("ecgiS: ");
+            ecgiS.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiS: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgiT != null) {
+            sb.append("ecgiT: ");
+            ecgiT.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgiT: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/L2MeasConfig.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/L2MeasConfig.java
new file mode 100644
index 0000000..16f00d0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/L2MeasConfig.java
@@ -0,0 +1,376 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.L2MeasReportInterval;
+import org.onosproject.xran.asn1lib.api.L2ReportInterval;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class L2MeasConfig implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private Crnti crnti = null;
+    private L2ReportInterval reportIntervals = null;
+
+    public L2MeasConfig() {
+    }
+
+    public L2MeasConfig(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, int l2MeasInterval) {
+        L2MeasConfig measConfig = new L2MeasConfig();
+        measConfig.setEcgi(ecgi);
+
+        L2ReportInterval l2ReportInterval = new L2ReportInterval();
+        L2MeasReportInterval l2MeasReportInterval = new L2MeasReportInterval(l2MeasInterval);
+        l2ReportInterval.setTPdcpMeasReportPerUe(l2MeasReportInterval);
+        l2ReportInterval.setTRadioMeasReportPerCell(l2MeasReportInterval);
+        l2ReportInterval.setTRadioMeasReportPerUe(l2MeasReportInterval);
+        l2ReportInterval.setTRadioSchedReportPerUe(l2MeasReportInterval);
+        l2ReportInterval.setTRadioSchedReportPerCell(l2MeasReportInterval);
+
+        measConfig.setReportIntervals(l2ReportInterval);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        XrancApiID apiID = new XrancApiID(16);
+        XrancPduBody body = new XrancPduBody();
+        body.setL2MeasConfig(measConfig);
+
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setBody(body);
+        pdu.setHdr(hdr);
+
+        return pdu;
+
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public Crnti getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(Crnti crnti) {
+        this.crnti = crnti;
+    }
+
+    public L2ReportInterval getReportIntervals() {
+        return reportIntervals;
+    }
+
+    public void setReportIntervals(L2ReportInterval reportIntervals) {
+        this.reportIntervals = reportIntervals;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += reportIntervals.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        if (crnti != null) {
+            codeLength += crnti.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            crnti = new Crnti();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            reportIntervals = new L2ReportInterval();
+            subCodeLength += reportIntervals.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (crnti != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("crnti: ");
+            crnti.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportIntervals != null) {
+            sb.append("reportIntervals: ");
+            reportIntervals.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("reportIntervals: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Crnti implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CRNTI> seqOf = null;
+
+        public Crnti() {
+            seqOf = new ArrayList<CRNTI>();
+        }
+
+        public Crnti(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<CRNTI> getCRNTI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CRNTI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CRNTI element = new CRNTI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CRNTI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/PDCPMeasReportPerUe.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/PDCPMeasReportPerUe.java
new file mode 100644
index 0000000..8765da9
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/PDCPMeasReportPerUe.java
@@ -0,0 +1,1788 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.QCI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class PDCPMeasReportPerUe implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private CRNTI crnti = null;
+    private QciVals qciVals = null;
+    private DataVolDl dataVolDl = null;
+    private DataVolUl dataVolUl = null;
+    private PktDelayDl pktDelayDl = null;
+    private PktDelayUl pktDelayUl = null;
+    private PktDiscardRateDl pktDiscardRateDl = null;
+    private PktLossRateDl pktLossRateDl = null;
+    private PktLossRateUl pktLossRateUl = null;
+    private ThroughputDl throughputDl = null;
+    private ThroughputUl throughputUl = null;
+
+    public PDCPMeasReportPerUe() {
+    }
+
+    public PDCPMeasReportPerUe(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public QciVals getQciVals() {
+        return qciVals;
+    }
+
+    public void setQciVals(QciVals qciVals) {
+        this.qciVals = qciVals;
+    }
+
+    public DataVolDl getDataVolDl() {
+        return dataVolDl;
+    }
+
+    public void setDataVolDl(DataVolDl dataVolDl) {
+        this.dataVolDl = dataVolDl;
+    }
+
+    public DataVolUl getDataVolUl() {
+        return dataVolUl;
+    }
+
+    public void setDataVolUl(DataVolUl dataVolUl) {
+        this.dataVolUl = dataVolUl;
+    }
+
+    public PktDelayDl getPktDelayDl() {
+        return pktDelayDl;
+    }
+
+    public void setPktDelayDl(PktDelayDl pktDelayDl) {
+        this.pktDelayDl = pktDelayDl;
+    }
+
+    public PktDelayUl getPktDelayUl() {
+        return pktDelayUl;
+    }
+
+    public void setPktDelayUl(PktDelayUl pktDelayUl) {
+        this.pktDelayUl = pktDelayUl;
+    }
+
+    public PktDiscardRateDl getPktDiscardRateDl() {
+        return pktDiscardRateDl;
+    }
+
+    public void setPktDiscardRateDl(PktDiscardRateDl pktDiscardRateDl) {
+        this.pktDiscardRateDl = pktDiscardRateDl;
+    }
+
+    public PktLossRateDl getPktLossRateDl() {
+        return pktLossRateDl;
+    }
+
+    public void setPktLossRateDl(PktLossRateDl pktLossRateDl) {
+        this.pktLossRateDl = pktLossRateDl;
+    }
+
+    public PktLossRateUl getPktLossRateUl() {
+        return pktLossRateUl;
+    }
+
+    public void setPktLossRateUl(PktLossRateUl pktLossRateUl) {
+        this.pktLossRateUl = pktLossRateUl;
+    }
+
+    public ThroughputDl getThroughputDl() {
+        return throughputDl;
+    }
+
+    public void setThroughputDl(ThroughputDl throughputDl) {
+        this.throughputDl = throughputDl;
+    }
+
+    public ThroughputUl getThroughputUl() {
+        return throughputUl;
+    }
+
+    public void setThroughputUl(ThroughputUl throughputUl) {
+        this.throughputUl = throughputUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += throughputUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 11
+        os.write(0xAB);
+        codeLength += 1;
+
+        codeLength += throughputDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 10
+        os.write(0xAA);
+        codeLength += 1;
+
+        codeLength += pktLossRateUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 9
+        os.write(0xA9);
+        codeLength += 1;
+
+        codeLength += pktLossRateDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 8
+        os.write(0xA8);
+        codeLength += 1;
+
+        codeLength += pktDiscardRateDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 7
+        os.write(0xA7);
+        codeLength += 1;
+
+        codeLength += pktDelayUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 6
+        os.write(0xA6);
+        codeLength += 1;
+
+        codeLength += pktDelayDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 5
+        os.write(0xA5);
+        codeLength += 1;
+
+        codeLength += dataVolUl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += dataVolDl.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += qciVals.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            qciVals = new QciVals();
+            subCodeLength += qciVals.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            dataVolDl = new DataVolDl();
+            subCodeLength += dataVolDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            dataVolUl = new DataVolUl();
+            subCodeLength += dataVolUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
+            pktDelayDl = new PktDelayDl();
+            subCodeLength += pktDelayDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) {
+            pktDelayUl = new PktDelayUl();
+            subCodeLength += pktDelayUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) {
+            pktDiscardRateDl = new PktDiscardRateDl();
+            subCodeLength += pktDiscardRateDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
+            pktLossRateDl = new PktLossRateDl();
+            subCodeLength += pktLossRateDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
+            pktLossRateUl = new PktLossRateUl();
+            subCodeLength += pktLossRateUl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
+            throughputDl = new ThroughputDl();
+            subCodeLength += throughputDl.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 11)) {
+            throughputUl = new ThroughputUl();
+            subCodeLength += throughputUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (qciVals != null) {
+            sb.append("qciVals: ");
+            qciVals.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("qciVals: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (dataVolDl != null) {
+            sb.append("dataVolDl: ");
+            dataVolDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("dataVolDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (dataVolUl != null) {
+            sb.append("dataVolUl: ");
+            dataVolUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("dataVolUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pktDelayDl != null) {
+            sb.append("pktDelayDl: ");
+            pktDelayDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pktDelayDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pktDelayUl != null) {
+            sb.append("pktDelayUl: ");
+            pktDelayUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pktDelayUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pktDiscardRateDl != null) {
+            sb.append("pktDiscardRateDl: ");
+            pktDiscardRateDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pktDiscardRateDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pktLossRateDl != null) {
+            sb.append("pktLossRateDl: ");
+            pktLossRateDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pktLossRateDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pktLossRateUl != null) {
+            sb.append("pktLossRateUl: ");
+            pktLossRateUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pktLossRateUl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (throughputDl != null) {
+            sb.append("throughputDl: ");
+            throughputDl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("throughputDl: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (throughputUl != null) {
+            sb.append("throughputUl: ");
+            throughputUl.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("throughputUl: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class QciVals implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<QCI> seqOf = null;
+
+        public QciVals() {
+            seqOf = new ArrayList<QCI>();
+        }
+
+        public QciVals(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<QCI> getQCI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<QCI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                QCI element = new QCI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<QCI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class DataVolDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public DataVolDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public DataVolDl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class DataVolUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public DataVolUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public DataVolUl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PktDelayDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PktDelayDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PktDelayDl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PktDelayUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PktDelayUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PktDelayUl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PktDiscardRateDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PktDiscardRateDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PktDiscardRateDl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PktLossRateDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PktLossRateDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PktLossRateDl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PktLossRateUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PktLossRateUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PktLossRateUl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class ThroughputDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public ThroughputDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public ThroughputDl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class ThroughputUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public ThroughputUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public ThroughputUl(byte[] code) {
+            this.code = code;
+        }
+
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRCMeasConfig.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRCMeasConfig.java
new file mode 100644
index 0000000..20b0980
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRCMeasConfig.java
@@ -0,0 +1,815 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.*;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RRCMeasConfig implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private Crnti crnti = null;
+    private MeasObjects measObjects = null;
+    private ReportConfigs reportConfigs = null;
+    private MeasIds measIds = null;
+
+    public RRCMeasConfig() {
+    }
+
+    public RRCMeasConfig(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(
+            ECGI ecgi, CRNTI crnti, MeasObjects measObjects, ReportConfigs reportConfigs,
+            MeasIds measIds, int rxSignalInterval
+    ) {
+        RRCMeasConfig rrcMeasConfig = new RRCMeasConfig();
+
+        Crnti crntilist = new Crnti();
+        crntilist.getCRNTI().add(crnti);
+
+        rrcMeasConfig.setEcgi(ecgi);
+        rrcMeasConfig.setCrnti(crntilist);
+        rrcMeasConfig.setMeasIds(measIds);
+        rrcMeasConfig.setMeasObjects(measObjects);
+        rrcMeasConfig.setReportConfigs(reportConfigs);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        XrancApiID apiID = new XrancApiID(34);
+        XrancPduBody body = new XrancPduBody();
+        body.setRRCMeasConfig(rrcMeasConfig);
+
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setBody(body);
+        pdu.setHdr(hdr);
+
+        return pdu;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public Crnti getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(Crnti crnti) {
+        this.crnti = crnti;
+    }
+
+    public MeasObjects getMeasObjects() {
+        return measObjects;
+    }
+
+    public void setMeasObjects(MeasObjects measObjects) {
+        this.measObjects = measObjects;
+    }
+
+    public ReportConfigs getReportConfigs() {
+        return reportConfigs;
+    }
+
+    public void setReportConfigs(ReportConfigs reportConfigs) {
+        this.reportConfigs = reportConfigs;
+    }
+
+    public MeasIds getMeasIds() {
+        return measIds;
+    }
+
+    public void setMeasIds(MeasIds measIds) {
+        this.measIds = measIds;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += measIds.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+        os.write(0xA4);
+        codeLength += 1;
+
+        codeLength += reportConfigs.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += measObjects.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        if (crnti != null) {
+            codeLength += crnti.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            crnti = new Crnti();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            measObjects = new MeasObjects();
+            subCodeLength += measObjects.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            reportConfigs = new ReportConfigs();
+            subCodeLength += reportConfigs.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            measIds = new MeasIds();
+            subCodeLength += measIds.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (crnti != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("crnti: ");
+            crnti.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (measObjects != null) {
+            sb.append("measObjects: ");
+            measObjects.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("measObjects: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reportConfigs != null) {
+            sb.append("reportConfigs: ");
+            reportConfigs.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("reportConfigs: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (measIds != null) {
+            sb.append("measIds: ");
+            measIds.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("measIds: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Crnti implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CRNTI> seqOf = null;
+
+        public Crnti() {
+            seqOf = new ArrayList<CRNTI>();
+        }
+
+        public Crnti(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<CRNTI> getCRNTI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CRNTI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CRNTI element = new CRNTI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CRNTI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class MeasObjects implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<MeasObject> seqOf = null;
+
+        public MeasObjects() {
+            seqOf = new ArrayList<MeasObject>();
+        }
+
+        public MeasObjects(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<MeasObject> getMeasObject() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<MeasObject>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                MeasObject element = new MeasObject();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<MeasObject> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class ReportConfigs implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<ReportConfig> seqOf = null;
+
+        public ReportConfigs() {
+            seqOf = new ArrayList<ReportConfig>();
+        }
+
+        public ReportConfigs(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<ReportConfig> getReportConfig() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<ReportConfig>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                ReportConfig element = new ReportConfig();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<ReportConfig> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class MeasIds implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<MeasID> seqOf = null;
+
+        public MeasIds() {
+            seqOf = new ArrayList<MeasID>();
+        }
+
+        public MeasIds(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<MeasID> getMeasID() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<MeasID>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                MeasID element = new MeasID();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<MeasID> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfig.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfig.java
new file mode 100644
index 0000000..196071c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfig.java
@@ -0,0 +1,1647 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.asn1lib.api.XICICPA;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RRMConfig implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private Crnti crnti = null;
+    private PCIARFCN pciArfcn = null;
+    private Pa pa = null;
+    private StartPrbDl startPrbDl = null;
+    private EndPrbDl endPrbDl = null;
+    private SubframeBitmaskDl subframeBitmaskDl = null;
+    private P0UePusch p0UePusch = null;
+    private StartPrbUl startPrbUl = null;
+    private EndPrbUl endPrbUl = null;
+    private SubframeBitmaskUl subframeBitmaskUl = null;
+
+    public RRMConfig() {
+    }
+
+    public static XrancPdu constructPacket(RRMConfig config) {
+        XrancPduBody body = new XrancPduBody();
+        body.setRRMConfig(config);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        XrancApiID apiID = new XrancApiID(27);
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setHdr(hdr);
+        pdu.setBody(body);
+        return pdu;
+    }
+
+    public RRMConfig(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public Crnti getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(Crnti crnti) {
+        this.crnti = crnti;
+    }
+
+    public PCIARFCN getPciArfcn() {
+        return pciArfcn;
+    }
+
+    public void setPciArfcn(PCIARFCN pciArfcn) {
+        this.pciArfcn = pciArfcn;
+    }
+
+    public Pa getPa() {
+        return pa;
+    }
+
+    public void setPa(Pa pa) {
+        this.pa = pa;
+    }
+
+    public StartPrbDl getStartPrbDl() {
+        return startPrbDl;
+    }
+
+    public void setStartPrbDl(StartPrbDl startPrbDl) {
+        this.startPrbDl = startPrbDl;
+    }
+
+    public EndPrbDl getEndPrbDl() {
+        return endPrbDl;
+    }
+
+    public void setEndPrbDl(EndPrbDl endPrbDl) {
+        this.endPrbDl = endPrbDl;
+    }
+
+    public SubframeBitmaskDl getSubframeBitmaskDl() {
+        return subframeBitmaskDl;
+    }
+
+    public void setSubframeBitmaskDl(SubframeBitmaskDl subframeBitmaskDl) {
+        this.subframeBitmaskDl = subframeBitmaskDl;
+    }
+
+    public P0UePusch getP0UePusch() {
+        return p0UePusch;
+    }
+
+    public void setP0UePusch(P0UePusch p0UePusch) {
+        this.p0UePusch = p0UePusch;
+    }
+
+    public StartPrbUl getStartPrbUl() {
+        return startPrbUl;
+    }
+
+    public void setStartPrbUl(StartPrbUl startPrbUl) {
+        this.startPrbUl = startPrbUl;
+    }
+
+    public EndPrbUl getEndPrbUl() {
+        return endPrbUl;
+    }
+
+    public void setEndPrbUl(EndPrbUl endPrbUl) {
+        this.endPrbUl = endPrbUl;
+    }
+
+    public SubframeBitmaskUl getSubframeBitmaskUl() {
+        return subframeBitmaskUl;
+    }
+
+    public void setSubframeBitmaskUl(SubframeBitmaskUl subframeBitmaskUl) {
+        this.subframeBitmaskUl = subframeBitmaskUl;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (subframeBitmaskUl != null) {
+            codeLength += subframeBitmaskUl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 10
+            os.write(0xAA);
+            codeLength += 1;
+        }
+
+        if (endPrbUl != null) {
+            codeLength += endPrbUl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 9
+            os.write(0xA9);
+            codeLength += 1;
+        }
+
+        if (startPrbUl != null) {
+            codeLength += startPrbUl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 8
+            os.write(0xA8);
+            codeLength += 1;
+        }
+
+        if (p0UePusch != null) {
+            codeLength += p0UePusch.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 7
+            os.write(0xA7);
+            codeLength += 1;
+        }
+
+        if (subframeBitmaskDl != null) {
+            codeLength += subframeBitmaskDl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 6
+            os.write(0xA6);
+            codeLength += 1;
+        }
+
+        if (endPrbDl != null) {
+            codeLength += endPrbDl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 5
+            os.write(0xA5);
+            codeLength += 1;
+        }
+
+        if (startPrbDl != null) {
+            codeLength += startPrbDl.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+            os.write(0xA4);
+            codeLength += 1;
+        }
+
+        if (pa != null) {
+            codeLength += pa.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+            os.write(0xA3);
+            codeLength += 1;
+        }
+
+        if (pciArfcn != null) {
+            codeLength += pciArfcn.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+            os.write(0xA2);
+            codeLength += 1;
+        }
+
+        if (crnti != null) {
+            codeLength += crnti.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            crnti = new Crnti();
+            subCodeLength += crnti.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            pciArfcn = new PCIARFCN();
+            subCodeLength += pciArfcn.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            pa = new Pa();
+            subCodeLength += pa.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+            startPrbDl = new StartPrbDl();
+            subCodeLength += startPrbDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
+            endPrbDl = new EndPrbDl();
+            subCodeLength += endPrbDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) {
+            subframeBitmaskDl = new SubframeBitmaskDl();
+            subCodeLength += subframeBitmaskDl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) {
+            p0UePusch = new P0UePusch();
+            subCodeLength += p0UePusch.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
+            startPrbUl = new StartPrbUl();
+            subCodeLength += startPrbUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
+            endPrbUl = new EndPrbUl();
+            subCodeLength += endPrbUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
+            subframeBitmaskUl = new SubframeBitmaskUl();
+            subCodeLength += subframeBitmaskUl.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (crnti != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("crnti: ");
+            crnti.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (pciArfcn != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("pciArfcn: ");
+            pciArfcn.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (pa != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("pa: ");
+            pa.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (startPrbDl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("startPrbDl: ");
+            startPrbDl.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (endPrbDl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("endPrbDl: ");
+            endPrbDl.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (subframeBitmaskDl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("subframeBitmaskDl: ");
+            subframeBitmaskDl.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (p0UePusch != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("p0UePusch: ");
+            p0UePusch.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (startPrbUl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("startPrbUl: ");
+            startPrbUl.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (endPrbUl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("endPrbUl: ");
+            endPrbUl.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (subframeBitmaskUl != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("subframeBitmaskUl: ");
+            subframeBitmaskUl.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Crnti implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CRNTI> seqOf = null;
+
+        public Crnti() {
+            seqOf = new ArrayList<CRNTI>();
+        }
+
+        public Crnti(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<CRNTI> getCRNTI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CRNTI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CRNTI element = new CRNTI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CRNTI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class Pa implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<XICICPA> seqOf = null;
+
+        public Pa() {
+            seqOf = new ArrayList<XICICPA>();
+        }
+
+        public Pa(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<XICICPA> getXICICPA() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<XICICPA>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                XICICPA element = new XICICPA();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<XICICPA> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class StartPrbDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public StartPrbDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public StartPrbDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class EndPrbDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public EndPrbDl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public EndPrbDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class SubframeBitmaskDl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerBitString> seqOf = null;
+
+        public SubframeBitmaskDl() {
+            seqOf = new ArrayList<BerBitString>();
+        }
+
+        public SubframeBitmaskDl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerBitString> getBerBitString() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerBitString>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerBitString element = new BerBitString();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerBitString> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class P0UePusch implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public P0UePusch() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public P0UePusch(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class StartPrbUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public StartPrbUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public StartPrbUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class EndPrbUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public EndPrbUl() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public EndPrbUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class SubframeBitmaskUl implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerBitString> seqOf = null;
+
+        public SubframeBitmaskUl() {
+            seqOf = new ArrayList<BerBitString>();
+        }
+
+        public SubframeBitmaskUl(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerBitString> getBerBitString() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerBitString>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerBitString element = new BerBitString();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerBitString> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfigStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfigStatus.java
new file mode 100644
index 0000000..009c0da
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RRMConfigStatus.java
@@ -0,0 +1,460 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RRMConfigStatus implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private Crnti crnti = null;
+    private Status status = null;
+
+    public RRMConfigStatus() {
+    }
+
+    public RRMConfigStatus(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public Crnti getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(Crnti crnti) {
+        this.crnti = crnti;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += status.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        if (crnti != null) {
+            codeLength += crnti.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+            os.write(0xA1);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            crnti = new Crnti();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            status = new Status();
+            subCodeLength += status.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (crnti != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("crnti: ");
+            crnti.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (status != null) {
+            sb.append("status: ");
+            status.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("status: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Crnti implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CRNTI> seqOf = null;
+
+        public Crnti() {
+            seqOf = new ArrayList<CRNTI>();
+        }
+
+        public Crnti(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<CRNTI> getCRNTI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CRNTI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CRNTI element = new CRNTI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CRNTI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class Status implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerEnum> seqOf = null;
+
+        public Status() {
+            seqOf = new ArrayList<BerEnum>();
+        }
+
+        public Status(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerEnum> getBerEnum() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerEnum>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerEnum element = new BerEnum();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerEnum> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RXSigMeasReport.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RXSigMeasReport.java
new file mode 100644
index 0000000..9e12d1f
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RXSigMeasReport.java
@@ -0,0 +1,588 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.RXSigReport;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RXSigMeasReport implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private Crnti crnti = null;
+    private ECGI ecgi = null;
+    private CellMeasReports cellMeasReports = null;
+
+    public RXSigMeasReport() {
+    }
+
+    public RXSigMeasReport(byte[] code) {
+        this.code = code;
+    }
+
+    public Crnti getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(Crnti crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CellMeasReports getCellMeasReports() {
+        return cellMeasReports;
+    }
+
+    public void setCellMeasReports(CellMeasReports cellMeasReports) {
+        this.cellMeasReports = cellMeasReports;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += cellMeasReports.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            crnti = new Crnti();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            cellMeasReports = new CellMeasReports();
+            subCodeLength += cellMeasReports.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ");
+            crnti.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (cellMeasReports != null) {
+            sb.append("cellMeasReports: ");
+            cellMeasReports.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("cellMeasReports: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class Crnti implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<CRNTI> seqOf = null;
+
+        public Crnti() {
+            seqOf = new ArrayList<CRNTI>();
+        }
+
+        public Crnti(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<CRNTI> getCRNTI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<CRNTI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                CRNTI element = new CRNTI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<CRNTI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class CellMeasReports implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<SEQUENCEOF> seqOf = null;
+
+        public CellMeasReports() {
+            seqOf = new ArrayList<SEQUENCEOF>();
+        }
+
+        public CellMeasReports(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<SEQUENCEOF> getSEQUENCEOF() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<SEQUENCEOF>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                SEQUENCEOF element = new SEQUENCEOF();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<SEQUENCEOF> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+        public static class SEQUENCEOF implements Serializable {
+
+            public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+            private static final long serialVersionUID = 1L;
+            @JsonIgnore
+            public byte[] code = null;
+            private List<RXSigReport> seqOf = null;
+
+            public SEQUENCEOF() {
+                seqOf = new ArrayList<RXSigReport>();
+            }
+
+            public SEQUENCEOF(byte[] code) {
+                this.code = code;
+            }
+
+            @JsonValue
+            public List<RXSigReport> getRXSigReport() {
+                if (seqOf == null) {
+                    seqOf = new ArrayList<RXSigReport>();
+                }
+                return seqOf;
+            }
+
+            public int encode(BerByteArrayOutputStream os) throws IOException {
+                return encode(os, true);
+            }
+
+            public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+                if (code != null) {
+                    for (int i = code.length - 1; i >= 0; i--) {
+                        os.write(code[i]);
+                    }
+                    if (withTag) {
+                        return tag.encode(os) + code.length;
+                    }
+                    return code.length;
+                }
+
+                int codeLength = 0;
+                for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                    codeLength += seqOf.get(i).encode(os, true);
+                }
+
+                codeLength += BerLength.encodeLength(os, codeLength);
+
+                if (withTag) {
+                    codeLength += tag.encode(os);
+                }
+
+                return codeLength;
+            }
+
+            public int decode(InputStream is) throws IOException {
+                return decode(is, true);
+            }
+
+            public int decode(InputStream is, boolean withTag) throws IOException {
+                int codeLength = 0;
+                int subCodeLength = 0;
+                if (withTag) {
+                    codeLength += tag.decodeAndCheck(is);
+                }
+
+                BerLength length = new BerLength();
+                codeLength += length.decode(is);
+                int totalLength = length.val;
+
+                while (subCodeLength < totalLength) {
+                    RXSigReport element = new RXSigReport();
+                    subCodeLength += element.decode(is, true);
+                    seqOf.add(element);
+                }
+                if (subCodeLength != totalLength) {
+                    throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+                }
+                codeLength += subCodeLength;
+
+                return codeLength;
+            }
+
+            public void encodeAndSave(int encodingSizeGuess) throws IOException {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+                encode(os, false);
+                code = os.getArray();
+            }
+
+            public String toString() {
+                StringBuilder sb = new StringBuilder();
+                appendAsString(sb, 0);
+                return sb.toString();
+            }
+
+            public void appendAsString(StringBuilder sb, int indentLevel) {
+
+                sb.append("{\n");
+                for (int i = 0; i < indentLevel + 1; i++) {
+                    sb.append("\t");
+                }
+                if (seqOf == null) {
+                    sb.append("null");
+                } else {
+                    Iterator<RXSigReport> it = seqOf.iterator();
+                    if (it.hasNext()) {
+                        it.next().appendAsString(sb, indentLevel + 1);
+                        while (it.hasNext()) {
+                            sb.append(",\n");
+                            for (int i = 0; i < indentLevel + 1; i++) {
+                                sb.append("\t");
+                            }
+                            it.next().appendAsString(sb, indentLevel + 1);
+                        }
+                    }
+                }
+
+                sb.append("\n");
+                for (int i = 0; i < indentLevel; i++) {
+                    sb.append("\t");
+                }
+                sb.append("}");
+            }
+
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerCell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerCell.java
new file mode 100644
index 0000000..60838a0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerCell.java
@@ -0,0 +1,461 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RadioMeasReportPerCell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private PuschIntfPowerHist puschIntfPowerHist = null;
+    private PucchIntfPowerHist pucchIntfPowerHist = null;
+
+    public RadioMeasReportPerCell() {
+    }
+
+    public RadioMeasReportPerCell(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public PuschIntfPowerHist getPuschIntfPowerHist() {
+        return puschIntfPowerHist;
+    }
+
+    public void setPuschIntfPowerHist(PuschIntfPowerHist puschIntfPowerHist) {
+        this.puschIntfPowerHist = puschIntfPowerHist;
+    }
+
+    public PucchIntfPowerHist getPucchIntfPowerHist() {
+        return pucchIntfPowerHist;
+    }
+
+    public void setPucchIntfPowerHist(PucchIntfPowerHist pucchIntfPowerHist) {
+        this.pucchIntfPowerHist = pucchIntfPowerHist;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += pucchIntfPowerHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += puschIntfPowerHist.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            puschIntfPowerHist = new PuschIntfPowerHist();
+            subCodeLength += puschIntfPowerHist.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            pucchIntfPowerHist = new PucchIntfPowerHist();
+            subCodeLength += pucchIntfPowerHist.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (puschIntfPowerHist != null) {
+            sb.append("puschIntfPowerHist: ");
+            puschIntfPowerHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("puschIntfPowerHist: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (pucchIntfPowerHist != null) {
+            sb.append("pucchIntfPowerHist: ");
+            pucchIntfPowerHist.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("pucchIntfPowerHist: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class PuschIntfPowerHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PuschIntfPowerHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PuschIntfPowerHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class PucchIntfPowerHist implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerInteger> seqOf = null;
+
+        public PucchIntfPowerHist() {
+            seqOf = new ArrayList<BerInteger>();
+        }
+
+        public PucchIntfPowerHist(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerInteger> getBerInteger() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerInteger>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerInteger element = new BerInteger();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerInteger> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerUE.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerUE.java
new file mode 100644
index 0000000..204060b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/RadioMeasReportPerUE.java
@@ -0,0 +1,335 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.RadioRepPerServCell;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class RadioMeasReportPerUE implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private CRNTI crnti = null;
+    private RadioReportServCells radioReportServCells = null;
+
+    public RadioMeasReportPerUE() {
+    }
+
+    public RadioMeasReportPerUE(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public RadioReportServCells getRadioReportServCells() {
+        return radioReportServCells;
+    }
+
+    public void setRadioReportServCells(RadioReportServCells radioReportServCells) {
+        this.radioReportServCells = radioReportServCells;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += radioReportServCells.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            radioReportServCells = new RadioReportServCells();
+            subCodeLength += radioReportServCells.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (radioReportServCells != null) {
+            sb.append("radioReportServCells: ");
+            radioReportServCells.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("radioReportServCells: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class RadioReportServCells implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<RadioRepPerServCell> seqOf = null;
+
+        public RadioReportServCells() {
+            seqOf = new ArrayList<RadioRepPerServCell>();
+        }
+
+        public RadioReportServCells(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<RadioRepPerServCell> getRadioRepPerServCell() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<RadioRepPerServCell>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                RadioRepPerServCell element = new RadioRepPerServCell();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<RadioRepPerServCell> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAdd.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAdd.java
new file mode 100644
index 0000000..5e524e9
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAdd.java
@@ -0,0 +1,374 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PropScell;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ScellAdd implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private ScellsProp scellsProp = null;
+
+    public ScellAdd() {
+    }
+
+    public ScellAdd(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, PropScell propScell) {
+        ScellAdd scellAdd = new ScellAdd();
+        scellAdd.setCrnti(crnti);
+        scellAdd.setEcgi(ecgi);
+
+        propScell.setCrossCarrierSchedEnable(new BerBoolean(true));
+        propScell.setCaDirection(new BerEnum(new BigInteger("dl")));
+        propScell.setDeactTimer(new BerInteger(1000));
+        ScellsProp scellsProp = new ScellsProp();
+        scellsProp.getPropScell().add(propScell);
+        scellAdd.setScellsProp(scellsProp);
+
+        XrancPduBody body = new XrancPduBody();
+        body.setScellAdd(scellAdd);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        XrancApiID apiID = new XrancApiID(24);
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setHdr(hdr);
+        pdu.setBody(body);
+
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public ScellsProp getScellsProp() {
+        return scellsProp;
+    }
+
+    public void setScellsProp(ScellsProp scellsProp) {
+        this.scellsProp = scellsProp;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += scellsProp.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            scellsProp = new ScellsProp();
+            subCodeLength += scellsProp.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (scellsProp != null) {
+            sb.append("scellsProp: ");
+            scellsProp.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("scellsProp: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class ScellsProp implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<PropScell> seqOf = null;
+
+        public ScellsProp() {
+            seqOf = new ArrayList<PropScell>();
+        }
+
+        public ScellsProp(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<PropScell> getPropScell() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<PropScell>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                PropScell element = new PropScell();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<PropScell> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAddStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAddStatus.java
new file mode 100644
index 0000000..ea29f54
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellAddStatus.java
@@ -0,0 +1,493 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ScellAddStatus implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private ScellsInd scellsInd = null;
+    private Status status = null;
+    public ScellAddStatus() {
+    }
+    public ScellAddStatus(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public ScellsInd getScellsInd() {
+        return scellsInd;
+    }
+
+    public void setScellsInd(ScellsInd scellsInd) {
+        this.scellsInd = scellsInd;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += status.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += scellsInd.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            scellsInd = new ScellsInd();
+            subCodeLength += scellsInd.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            status = new Status();
+            subCodeLength += status.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (scellsInd != null) {
+            sb.append("scellsInd: ");
+            scellsInd.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("scellsInd: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (status != null) {
+            sb.append("status: ");
+            status.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("status: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class ScellsInd implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<PCIARFCN> seqOf = null;
+
+        public ScellsInd() {
+            seqOf = new ArrayList<PCIARFCN>();
+        }
+
+        public ScellsInd(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<PCIARFCN> getPCIARFCN() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<PCIARFCN>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                PCIARFCN element = new PCIARFCN();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<PCIARFCN> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+    public static class Status implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<BerEnum> seqOf = null;
+
+        public Status() {
+            seqOf = new ArrayList<BerEnum>();
+        }
+
+        public Status(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<BerEnum> getBerEnum() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<BerEnum>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                BerEnum element = new BerEnum();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<BerEnum> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellDelete.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellDelete.java
new file mode 100644
index 0000000..a17b221
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/ScellDelete.java
@@ -0,0 +1,367 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ScellDelete implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private ScellsInd scellsInd = null;
+
+    public ScellDelete() {
+    }
+
+    public ScellDelete(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, PCIARFCN pciarfcn) {
+        ScellDelete scellDelete = new ScellDelete();
+        scellDelete.setEcgi(ecgi);
+        scellDelete.setCrnti(crnti);
+        ScellsInd scellsInd = new ScellsInd();
+        scellsInd.getPCIARFCN().add(pciarfcn);
+        scellDelete.setScellsInd(scellsInd);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        XrancApiID apiID = new XrancApiID(26);
+        XrancPduBody body = new XrancPduBody();
+        body.setScellDelete(scellDelete);
+
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setBody(body);
+        pdu.setHdr(hdr);
+
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public ScellsInd getScellsInd() {
+        return scellsInd;
+    }
+
+    public void setScellsInd(ScellsInd scellsInd) {
+        this.scellsInd = scellsInd;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += scellsInd.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            scellsInd = new ScellsInd();
+            subCodeLength += scellsInd.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (scellsInd != null) {
+            sb.append("scellsInd: ");
+            scellsInd.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("scellsInd: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class ScellsInd implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<PCIARFCN> seqOf = null;
+
+        public ScellsInd() {
+            seqOf = new ArrayList<PCIARFCN>();
+        }
+
+        public ScellsInd(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<PCIARFCN> getPCIARFCN() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<PCIARFCN>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                PCIARFCN element = new PCIARFCN();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<PCIARFCN> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerCell.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerCell.java
new file mode 100644
index 0000000..e926702
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerCell.java
@@ -0,0 +1,369 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PRBUsage;
+import org.onosproject.xran.asn1lib.api.QCI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class SchedMeasReportPerCell implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private QciVals qciVals = null;
+    private PRBUsage prbUsagePcell = null;
+    private PRBUsage prbUsageScell = null;
+
+    public SchedMeasReportPerCell() {
+    }
+
+    public SchedMeasReportPerCell(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public QciVals getQciVals() {
+        return qciVals;
+    }
+
+    public void setQciVals(QciVals qciVals) {
+        this.qciVals = qciVals;
+    }
+
+    public PRBUsage getPrbUsagePcell() {
+        return prbUsagePcell;
+    }
+
+    public void setPrbUsagePcell(PRBUsage prbUsagePcell) {
+        this.prbUsagePcell = prbUsagePcell;
+    }
+
+    public PRBUsage getPrbUsageScell() {
+        return prbUsageScell;
+    }
+
+    public void setPrbUsageScell(PRBUsage prbUsageScell) {
+        this.prbUsageScell = prbUsageScell;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += prbUsageScell.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+        os.write(0xA3);
+        codeLength += 1;
+
+        codeLength += prbUsagePcell.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += qciVals.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            qciVals = new QciVals();
+            subCodeLength += qciVals.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            prbUsagePcell = new PRBUsage();
+            subCodeLength += prbUsagePcell.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            prbUsageScell = new PRBUsage();
+            subCodeLength += prbUsageScell.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (qciVals != null) {
+            sb.append("qciVals: ");
+            qciVals.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("qciVals: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (prbUsagePcell != null) {
+            sb.append("prbUsagePcell: ");
+            prbUsagePcell.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("prbUsagePcell: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (prbUsageScell != null) {
+            sb.append("prbUsageScell: ");
+            prbUsageScell.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("prbUsageScell: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class QciVals implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<QCI> seqOf = null;
+
+        public QciVals() {
+            seqOf = new ArrayList<QCI>();
+        }
+
+        public QciVals(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<QCI> getQCI() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<QCI>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                QCI element = new QCI();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<QCI> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    sb.append(it.next());
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        sb.append(it.next());
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerUE.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerUE.java
new file mode 100644
index 0000000..211ea0f
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SchedMeasReportPerUE.java
@@ -0,0 +1,335 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.SchedMeasRepPerServCell;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class SchedMeasReportPerUE implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private ECGI ecgi = null;
+    private CRNTI crnti = null;
+    private SchedReportServCells schedReportServCells = null;
+
+    public SchedMeasReportPerUE() {
+    }
+
+    public SchedMeasReportPerUE(byte[] code) {
+        this.code = code;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public SchedReportServCells getSchedReportServCells() {
+        return schedReportServCells;
+    }
+
+    public void setSchedReportServCells(SchedReportServCells schedReportServCells) {
+        this.schedReportServCells = schedReportServCells;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += schedReportServCells.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 1
+        os.write(0x81);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+        os.write(0xA0);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            schedReportServCells = new SchedReportServCells();
+            subCodeLength += schedReportServCells.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (schedReportServCells != null) {
+            sb.append("schedReportServCells: ");
+            schedReportServCells.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("schedReportServCells: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class SchedReportServCells implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<SchedMeasRepPerServCell> seqOf = null;
+
+        public SchedReportServCells() {
+            seqOf = new ArrayList<SchedMeasRepPerServCell>();
+        }
+
+        public SchedReportServCells(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<SchedMeasRepPerServCell> getSchedMeasRepPerServCell() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<SchedMeasRepPerServCell>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                SchedMeasRepPerServCell element = new SchedMeasRepPerServCell();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<SchedMeasRepPerServCell> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAdd.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAdd.java
new file mode 100644
index 0000000..df99522
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAdd.java
@@ -0,0 +1,204 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class SeNBAdd implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI mEcgi = null;
+    private ECGI sEcgi = null;
+
+    public SeNBAdd() {
+    }
+
+    public SeNBAdd(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getMEcgi() {
+        return mEcgi;
+    }
+
+    public void setMEcgi(ECGI mEcgi) {
+        this.mEcgi = mEcgi;
+    }
+
+    public ECGI getSEcgi() {
+        return sEcgi;
+    }
+
+    public void setSEcgi(ECGI sEcgi) {
+        this.sEcgi = sEcgi;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += sEcgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += mEcgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            mEcgi = new ECGI();
+            subCodeLength += mEcgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            sEcgi = new ECGI();
+            subCodeLength += sEcgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mEcgi != null) {
+            sb.append("mEcgi: ");
+            mEcgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("mEcgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (sEcgi != null) {
+            sb.append("sEcgi: ");
+            sEcgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("sEcgi: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAddStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAddStatus.java
new file mode 100644
index 0000000..e68799b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBAddStatus.java
@@ -0,0 +1,204 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class SeNBAddStatus implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private BerEnum status = null;
+
+    public SeNBAddStatus() {
+    }
+
+    public SeNBAddStatus(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public BerEnum getStatus() {
+        return status;
+    }
+
+    public void setStatus(BerEnum status) {
+        this.status = status;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += status.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            status = new BerEnum();
+            subCodeLength += status.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (status != null) {
+            sb.append("status: ").append(status);
+        } else {
+            sb.append("status: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBDelete.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBDelete.java
new file mode 100644
index 0000000..35fc047
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/SeNBDelete.java
@@ -0,0 +1,204 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class SeNBDelete implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI mEcgi = null;
+    private ECGI sEcgi = null;
+
+    public SeNBDelete() {
+    }
+
+    public SeNBDelete(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getMEcgi() {
+        return mEcgi;
+    }
+
+    public void setMEcgi(ECGI mEcgi) {
+        this.mEcgi = mEcgi;
+    }
+
+    public ECGI getSEcgi() {
+        return sEcgi;
+    }
+
+    public void setSEcgi(ECGI sEcgi) {
+        this.sEcgi = sEcgi;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += sEcgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += mEcgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            mEcgi = new ECGI();
+            subCodeLength += mEcgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            sEcgi = new ECGI();
+            subCodeLength += sEcgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mEcgi != null) {
+            sb.append("mEcgi: ");
+            mEcgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("mEcgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (sEcgi != null) {
+            sb.append("sEcgi: ");
+            sEcgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("sEcgi: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/TrafficSplitConfig.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/TrafficSplitConfig.java
new file mode 100644
index 0000000..ebdc917
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/TrafficSplitConfig.java
@@ -0,0 +1,335 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonValue;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.TrafficSplitPercentage;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class TrafficSplitConfig implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private TrafficSplitPercent trafficSplitPercent = null;
+
+    public TrafficSplitConfig() {
+    }
+
+    public TrafficSplitConfig(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public TrafficSplitPercent getTrafficSplitPercent() {
+        return trafficSplitPercent;
+    }
+
+    public void setTrafficSplitPercent(TrafficSplitPercent trafficSplitPercent) {
+        this.trafficSplitPercent = trafficSplitPercent;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += trafficSplitPercent.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+        os.write(0xA2);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            trafficSplitPercent = new TrafficSplitPercent();
+            subCodeLength += trafficSplitPercent.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (trafficSplitPercent != null) {
+            sb.append("trafficSplitPercent: ");
+            trafficSplitPercent.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("trafficSplitPercent: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+    public static class TrafficSplitPercent implements Serializable {
+
+        public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+        private static final long serialVersionUID = 1L;
+        @JsonIgnore
+        public byte[] code = null;
+        private List<TrafficSplitPercentage> seqOf = null;
+
+        public TrafficSplitPercent() {
+            seqOf = new ArrayList<TrafficSplitPercentage>();
+        }
+
+        public TrafficSplitPercent(byte[] code) {
+            this.code = code;
+        }
+
+        @JsonValue
+        public List<TrafficSplitPercentage> getTrafficSplitPercentage() {
+            if (seqOf == null) {
+                seqOf = new ArrayList<TrafficSplitPercentage>();
+            }
+            return seqOf;
+        }
+
+        public int encode(BerByteArrayOutputStream os) throws IOException {
+            return encode(os, true);
+        }
+
+        public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+            if (code != null) {
+                for (int i = code.length - 1; i >= 0; i--) {
+                    os.write(code[i]);
+                }
+                if (withTag) {
+                    return tag.encode(os) + code.length;
+                }
+                return code.length;
+            }
+
+            int codeLength = 0;
+            for (int i = (seqOf.size() - 1); i >= 0; i--) {
+                codeLength += seqOf.get(i).encode(os, true);
+            }
+
+            codeLength += BerLength.encodeLength(os, codeLength);
+
+            if (withTag) {
+                codeLength += tag.encode(os);
+            }
+
+            return codeLength;
+        }
+
+        public int decode(InputStream is) throws IOException {
+            return decode(is, true);
+        }
+
+        public int decode(InputStream is, boolean withTag) throws IOException {
+            int codeLength = 0;
+            int subCodeLength = 0;
+            if (withTag) {
+                codeLength += tag.decodeAndCheck(is);
+            }
+
+            BerLength length = new BerLength();
+            codeLength += length.decode(is);
+            int totalLength = length.val;
+
+            while (subCodeLength < totalLength) {
+                TrafficSplitPercentage element = new TrafficSplitPercentage();
+                subCodeLength += element.decode(is, true);
+                seqOf.add(element);
+            }
+            if (subCodeLength != totalLength) {
+                throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
+
+            }
+            codeLength += subCodeLength;
+
+            return codeLength;
+        }
+
+        public void encodeAndSave(int encodingSizeGuess) throws IOException {
+            BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+            encode(os, false);
+            code = os.getArray();
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            appendAsString(sb, 0);
+            return sb.toString();
+        }
+
+        public void appendAsString(StringBuilder sb, int indentLevel) {
+
+            sb.append("{\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            if (seqOf == null) {
+                sb.append("null");
+            } else {
+                Iterator<TrafficSplitPercentage> it = seqOf.iterator();
+                if (it.hasNext()) {
+                    it.next().appendAsString(sb, indentLevel + 1);
+                    while (it.hasNext()) {
+                        sb.append(",\n");
+                        for (int i = 0; i < indentLevel + 1; i++) {
+                            sb.append("\t");
+                        }
+                        it.next().appendAsString(sb, indentLevel + 1);
+                    }
+                }
+            }
+
+            sb.append("\n");
+            for (int i = 0; i < indentLevel; i++) {
+                sb.append("\t");
+            }
+            sb.append("}");
+        }
+
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionRequest.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionRequest.java
new file mode 100644
index 0000000..b807e50
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionRequest.java
@@ -0,0 +1,211 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.AdmEstCause;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UEAdmissionRequest implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+
+	@JsonIgnore
+	public byte[] code = null;
+	private CRNTI crnti = null;
+	private ECGI ecgi = null;
+	private AdmEstCause admEstCause = null;
+	
+	public UEAdmissionRequest() {
+	}
+
+	public UEAdmissionRequest(byte[] code) {
+		this.code = code;
+	}
+
+	public void setCrnti(CRNTI crnti) {
+		this.crnti = crnti;
+	}
+
+	public CRNTI getCrnti() {
+		return crnti;
+	}
+
+	public void setEcgi(ECGI ecgi) {
+		this.ecgi = ecgi;
+	}
+
+	public ECGI getEcgi() {
+		return ecgi;
+	}
+
+	public void setAdmEstCause(AdmEstCause admEstCause) {
+		this.admEstCause = admEstCause;
+	}
+
+	public AdmEstCause getAdmEstCause() {
+		return admEstCause;
+	}
+
+	public int encode(BerByteArrayOutputStream os) throws IOException {
+		return encode(os, true);
+	}
+
+	public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+		if (code != null) {
+			for (int i = code.length - 1; i >= 0; i--) {
+				os.write(code[i]);
+			}
+			if (withTag) {
+				return tag.encode(os) + code.length;
+			}
+			return code.length;
+		}
+
+		int codeLength = 0;
+		codeLength += admEstCause.encode(os, false);
+		// write tag: CONTEXT_CLASS, PRIMITIVE, 2
+		os.write(0x82);
+		codeLength += 1;
+		
+		codeLength += ecgi.encode(os, false);
+		// write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+		os.write(0xA1);
+		codeLength += 1;
+		
+		codeLength += crnti.encode(os, false);
+		// write tag: CONTEXT_CLASS, PRIMITIVE, 0
+		os.write(0x80);
+		codeLength += 1;
+		
+		codeLength += BerLength.encodeLength(os, codeLength);
+
+		if (withTag) {
+			codeLength += tag.encode(os);
+		}
+
+		return codeLength;
+
+	}
+
+	public int decode(InputStream is) throws IOException {
+		return decode(is, true);
+	}
+
+	public int decode(InputStream is, boolean withTag) throws IOException {
+		int codeLength = 0;
+		int subCodeLength = 0;
+		BerTag berTag = new BerTag();
+
+		if (withTag) {
+			codeLength += tag.decodeAndCheck(is);
+		}
+
+		BerLength length = new BerLength();
+		codeLength += length.decode(is);
+
+		int totalLength = length.val;
+		codeLength += totalLength;
+
+		subCodeLength += berTag.decode(is);
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+			crnti = new CRNTI();
+			subCodeLength += crnti.decode(is, false);
+			subCodeLength += berTag.decode(is);
+		}
+		else {
+			throw new IOException("Tag does not match the mandatory sequence element tag.");
+		}
+		
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+			ecgi = new ECGI();
+			subCodeLength += ecgi.decode(is, false);
+			subCodeLength += berTag.decode(is);
+		}
+		else {
+			throw new IOException("Tag does not match the mandatory sequence element tag.");
+		}
+		
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+			admEstCause = new AdmEstCause();
+			subCodeLength += admEstCause.decode(is, false);
+			if (subCodeLength == totalLength) {
+				return codeLength;
+			}
+		}
+		throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+		
+	}
+
+	public void encodeAndSave(int encodingSizeGuess) throws IOException {
+		BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+		encode(os, false);
+		code = os.getArray();
+	}
+
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		appendAsString(sb, 0);
+		return sb.toString();
+	}
+
+	public void appendAsString(StringBuilder sb, int indentLevel) {
+
+		sb.append("{");
+		sb.append("\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (crnti != null) {
+			sb.append("crnti: ").append(crnti);
+		}
+		else {
+			sb.append("crnti: <empty-required-field>");
+		}
+		
+		sb.append(",\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (ecgi != null) {
+			sb.append("ecgi: ");
+			ecgi.appendAsString(sb, indentLevel + 1);
+		}
+		else {
+			sb.append("ecgi: <empty-required-field>");
+		}
+		
+		sb.append(",\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (admEstCause != null) {
+			sb.append("admEstCause: ").append(admEstCause);
+		}
+		else {
+			sb.append("admEstCause: <empty-required-field>");
+		}
+		
+		sb.append("\n");
+		for (int i = 0; i < indentLevel; i++) {
+			sb.append("\t");
+		}
+		sb.append("}");
+	}
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionResponse.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionResponse.java
new file mode 100644
index 0000000..e06c0fd
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionResponse.java
@@ -0,0 +1,234 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.AdmEstResponse;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+
+public class UEAdmissionResponse implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private AdmEstResponse admEstResponse = null;
+
+    public UEAdmissionResponse() {
+    }
+
+    public UEAdmissionResponse(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, boolean b) {
+        AdmEstResponse response = new AdmEstResponse(b ? 0 : 1);
+
+        UEAdmissionResponse ueAdmissionResponse = new UEAdmissionResponse();
+        ueAdmissionResponse.setCrnti(crnti);
+        ueAdmissionResponse.setEcgi(ecgi);
+        ueAdmissionResponse.setAdmEstResponse(response);
+
+        XrancPduBody body = new XrancPduBody();
+        body.setUEAdmissionResponse(ueAdmissionResponse);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        XrancApiID apiID = new XrancApiID(3);
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setHdr(hdr);
+        pdu.setBody(body);
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public AdmEstResponse getAdmEstResponse() {
+        return admEstResponse;
+    }
+
+    public void setAdmEstResponse(AdmEstResponse admEstResponse) {
+        this.admEstResponse = admEstResponse;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += admEstResponse.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            admEstResponse = new AdmEstResponse();
+            subCodeLength += admEstResponse.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (admEstResponse != null) {
+            sb.append("admEstResponse: ").append(admEstResponse);
+        } else {
+            sb.append("admEstResponse: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionStatus.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionStatus.java
new file mode 100644
index 0000000..137bf60
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEAdmissionStatus.java
@@ -0,0 +1,204 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.AdmEstStatus;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UEAdmissionStatus implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private AdmEstStatus admEstStatus = null;
+
+    public UEAdmissionStatus() {
+    }
+
+    public UEAdmissionStatus(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public AdmEstStatus getAdmEstStatus() {
+        return admEstStatus;
+    }
+
+    public void setAdmEstStatus(AdmEstStatus admEstStatus) {
+        this.admEstStatus = admEstStatus;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += admEstStatus.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            admEstStatus = new AdmEstStatus();
+            subCodeLength += admEstStatus.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (admEstStatus != null) {
+            sb.append("admEstStatus: ").append(admEstStatus);
+        } else {
+            sb.append("admEstStatus: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityEnquiry.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityEnquiry.java
new file mode 100644
index 0000000..ceb3b79
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityEnquiry.java
@@ -0,0 +1,199 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+
+public class UECapabilityEnquiry implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+
+    public UECapabilityEnquiry() {
+    }
+
+    public UECapabilityEnquiry(byte[] code) {
+        this.code = code;
+    }
+
+    public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti) {
+        UECapabilityEnquiry capabilityEnquiry = new UECapabilityEnquiry();
+        capabilityEnquiry.setCrnti(crnti);
+        capabilityEnquiry.setEcgi(ecgi);
+
+        XrancPduBody body = new XrancPduBody();
+        body.setUECapabilityEnquiry(capabilityEnquiry);
+
+        BerUTF8String ver = null;
+        try {
+            ver = new BerUTF8String("5");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        XrancApiID apiID = new XrancApiID(22);
+        XrancPduHdr hdr = new XrancPduHdr();
+        hdr.setVer(ver);
+        hdr.setApiId(apiID);
+
+        XrancPdu pdu = new XrancPdu();
+        pdu.setHdr(hdr);
+        pdu.setBody(body);
+
+        return pdu;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityInfo.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityInfo.java
new file mode 100644
index 0000000..b842ec4
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UECapabilityInfo.java
@@ -0,0 +1,243 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CACap;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.DCCap;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UECapabilityInfo implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private CACap caCap = null;
+    private DCCap dcCap = null;
+
+    public UECapabilityInfo() {
+    }
+
+    public UECapabilityInfo(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CACap getCaCap() {
+        return caCap;
+    }
+
+    public void setCaCap(CACap caCap) {
+        this.caCap = caCap;
+    }
+
+    public DCCap getDcCap() {
+        return dcCap;
+    }
+
+    public void setDcCap(DCCap dcCap) {
+        this.dcCap = dcCap;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (dcCap != null) {
+            codeLength += dcCap.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+            os.write(0xA3);
+            codeLength += 1;
+        }
+
+        if (caCap != null) {
+            codeLength += caCap.encode(os, false);
+            // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+            os.write(0xA2);
+            codeLength += 1;
+        }
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+            caCap = new CACap();
+            subCodeLength += caCap.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+            dcCap = new DCCap();
+            subCodeLength += dcCap.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        if (caCap != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("caCap: ");
+            caCap.appendAsString(sb, indentLevel + 1);
+        }
+
+        if (dcCap != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("dcCap: ");
+            dcCap.appendAsString(sb, indentLevel + 1);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEContextUpdate.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEContextUpdate.java
new file mode 100644
index 0000000..310cc7d
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEContextUpdate.java
@@ -0,0 +1,273 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ENBUES1APID;
+import org.onosproject.xran.asn1lib.api.MMEUES1APID;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UEContextUpdate implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private MMEUES1APID mMEUES1APID = null;
+    private ENBUES1APID eNBUES1APID = null;
+    private BerUTF8String imsi = null;
+
+    public UEContextUpdate() {
+    }
+
+    public UEContextUpdate(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public MMEUES1APID getMMEUES1APID() {
+        return mMEUES1APID;
+    }
+
+    public void setMMEUES1APID(MMEUES1APID mMEUES1APID) {
+        this.mMEUES1APID = mMEUES1APID;
+    }
+
+    public ENBUES1APID getENBUES1APID() {
+        return eNBUES1APID;
+    }
+
+    public void setENBUES1APID(ENBUES1APID eNBUES1APID) {
+        this.eNBUES1APID = eNBUES1APID;
+    }
+
+    public BerUTF8String getImsi() {
+        return imsi;
+    }
+
+    public void setImsi(BerUTF8String imsi) {
+        this.imsi = imsi;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        if (imsi != null) {
+            codeLength += imsi.encode(os, false);
+            // write tag: CONTEXT_CLASS, PRIMITIVE, 4
+            os.write(0x84);
+            codeLength += 1;
+        }
+
+        codeLength += eNBUES1APID.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += mMEUES1APID.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            mMEUES1APID = new MMEUES1APID();
+            subCodeLength += mMEUES1APID.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            eNBUES1APID = new ENBUES1APID();
+            subCodeLength += eNBUES1APID.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
+            imsi = new BerUTF8String();
+            subCodeLength += imsi.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (mMEUES1APID != null) {
+            sb.append("mMEUES1APID: ").append(mMEUES1APID);
+        } else {
+            sb.append("mMEUES1APID: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (eNBUES1APID != null) {
+            sb.append("eNBUES1APID: ").append(eNBUES1APID);
+        } else {
+            sb.append("eNBUES1APID: <empty-required-field>");
+        }
+
+        if (imsi != null) {
+            sb.append(",\n");
+            for (int i = 0; i < indentLevel + 1; i++) {
+                sb.append("\t");
+            }
+            sb.append("imsi: ").append(imsi);
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReconfigInd.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReconfigInd.java
new file mode 100644
index 0000000..3d7fe2e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReconfigInd.java
@@ -0,0 +1,236 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ReconfIndReason;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UEReconfigInd implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crntiOld = null;
+    private ECGI ecgi = null;
+    private CRNTI crntiNew = null;
+    private ReconfIndReason reconfigCause = null;
+
+    public UEReconfigInd() {
+    }
+
+    public UEReconfigInd(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrntiOld() {
+        return crntiOld;
+    }
+
+    public void setCrntiOld(CRNTI crntiOld) {
+        this.crntiOld = crntiOld;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public CRNTI getCrntiNew() {
+        return crntiNew;
+    }
+
+    public void setCrntiNew(CRNTI crntiNew) {
+        this.crntiNew = crntiNew;
+    }
+
+    public ReconfIndReason getReconfigCause() {
+        return reconfigCause;
+    }
+
+    public void setReconfigCause(ReconfIndReason reconfigCause) {
+        this.reconfigCause = reconfigCause;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += reconfigCause.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 3
+        os.write(0x83);
+        codeLength += 1;
+
+        codeLength += crntiNew.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crntiOld.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crntiOld = new CRNTI();
+            subCodeLength += crntiOld.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            crntiNew = new CRNTI();
+            subCodeLength += crntiNew.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
+            reconfigCause = new ReconfIndReason();
+            subCodeLength += reconfigCause.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crntiOld != null) {
+            sb.append("crntiOld: ").append(crntiOld);
+        } else {
+            sb.append("crntiOld: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crntiNew != null) {
+            sb.append("crntiNew: ").append(crntiNew);
+        } else {
+            sb.append("crntiNew: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (reconfigCause != null) {
+            sb.append("reconfigCause: ").append(reconfigCause);
+        } else {
+            sb.append("reconfigCause: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReleaseInd.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReleaseInd.java
new file mode 100644
index 0000000..dd4f717
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/UEReleaseInd.java
@@ -0,0 +1,204 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.RelCause;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class UEReleaseInd implements Serializable {
+
+    public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+    private static final long serialVersionUID = 1L;
+    @JsonIgnore
+    public byte[] code = null;
+    private CRNTI crnti = null;
+    private ECGI ecgi = null;
+    private RelCause releaseCause = null;
+
+    public UEReleaseInd() {
+    }
+
+    public UEReleaseInd(byte[] code) {
+        this.code = code;
+    }
+
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    public RelCause getReleaseCause() {
+        return releaseCause;
+    }
+
+    public void setReleaseCause(RelCause releaseCause) {
+        this.releaseCause = releaseCause;
+    }
+
+    public int encode(BerByteArrayOutputStream os) throws IOException {
+        return encode(os, true);
+    }
+
+    public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+        if (code != null) {
+            for (int i = code.length - 1; i >= 0; i--) {
+                os.write(code[i]);
+            }
+            if (withTag) {
+                return tag.encode(os) + code.length;
+            }
+            return code.length;
+        }
+
+        int codeLength = 0;
+        codeLength += releaseCause.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 2
+        os.write(0x82);
+        codeLength += 1;
+
+        codeLength += ecgi.encode(os, false);
+        // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+        os.write(0xA1);
+        codeLength += 1;
+
+        codeLength += crnti.encode(os, false);
+        // write tag: CONTEXT_CLASS, PRIMITIVE, 0
+        os.write(0x80);
+        codeLength += 1;
+
+        codeLength += BerLength.encodeLength(os, codeLength);
+
+        if (withTag) {
+            codeLength += tag.encode(os);
+        }
+
+        return codeLength;
+
+    }
+
+    public int decode(InputStream is) throws IOException {
+        return decode(is, true);
+    }
+
+    public int decode(InputStream is, boolean withTag) throws IOException {
+        int codeLength = 0;
+        int subCodeLength = 0;
+        BerTag berTag = new BerTag();
+
+        if (withTag) {
+            codeLength += tag.decodeAndCheck(is);
+        }
+
+        BerLength length = new BerLength();
+        codeLength += length.decode(is);
+
+        int totalLength = length.val;
+        codeLength += totalLength;
+
+        subCodeLength += berTag.decode(is);
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+            crnti = new CRNTI();
+            subCodeLength += crnti.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+            ecgi = new ECGI();
+            subCodeLength += ecgi.decode(is, false);
+            subCodeLength += berTag.decode(is);
+        } else {
+            throw new IOException("Tag does not match the mandatory sequence element tag.");
+        }
+
+        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
+            releaseCause = new RelCause();
+            subCodeLength += releaseCause.decode(is, false);
+            if (subCodeLength == totalLength) {
+                return codeLength;
+            }
+        }
+        throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+
+    }
+
+    public void encodeAndSave(int encodingSizeGuess) throws IOException {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+        encode(os, false);
+        code = os.getArray();
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        appendAsString(sb, 0);
+        return sb.toString();
+    }
+
+    public void appendAsString(StringBuilder sb, int indentLevel) {
+
+        sb.append("{");
+        sb.append("\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (crnti != null) {
+            sb.append("crnti: ").append(crnti);
+        } else {
+            sb.append("crnti: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (ecgi != null) {
+            sb.append("ecgi: ");
+            ecgi.appendAsString(sb, indentLevel + 1);
+        } else {
+            sb.append("ecgi: <empty-required-field>");
+        }
+
+        sb.append(",\n");
+        for (int i = 0; i < indentLevel + 1; i++) {
+            sb.append("\t");
+        }
+        if (releaseCause != null) {
+            sb.append("releaseCause: ").append(releaseCause);
+        } else {
+            sb.append("releaseCause: <empty-required-field>");
+        }
+
+        sb.append("\n");
+        for (int i = 0; i < indentLevel; i++) {
+            sb.append("\t");
+        }
+        sb.append("}");
+    }
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancApiID.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancApiID.java
new file mode 100644
index 0000000..c258f10
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancApiID.java
@@ -0,0 +1,31 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+
+import java.math.BigInteger;
+
+public class XrancApiID extends BerEnum {
+
+	private static final long serialVersionUID = 1L;
+
+	public XrancApiID() {
+	}
+
+	public XrancApiID(byte[] code) {
+		super(code);
+	}
+
+	public XrancApiID(BigInteger value) {
+		super(value);
+	}
+
+	public XrancApiID(long value) {
+		super(value);
+	}
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPdu.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPdu.java
new file mode 100644
index 0000000..2253dd1
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPdu.java
@@ -0,0 +1,179 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class XrancPdu implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+
+	public byte[] code = null;
+	private XrancPduHdr hdr = null;
+	private XrancPduBody body = null;
+	
+	public XrancPdu() {
+	}
+
+	public XrancPdu(byte[] code) {
+		this.code = code;
+	}
+
+	public void setHdr(XrancPduHdr hdr) {
+		this.hdr = hdr;
+	}
+
+	public XrancPduHdr getHdr() {
+		return hdr;
+	}
+
+	public void setBody(XrancPduBody body) {
+		this.body = body;
+	}
+
+	public XrancPduBody getBody() {
+		return body;
+	}
+
+	public int encode(BerByteArrayOutputStream os) throws IOException {
+		return encode(os, true);
+	}
+
+	public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+		if (code != null) {
+			for (int i = code.length - 1; i >= 0; i--) {
+				os.write(code[i]);
+			}
+			if (withTag) {
+				return tag.encode(os) + code.length;
+			}
+			return code.length;
+		}
+
+		int codeLength = 0;
+		int sublength;
+
+		sublength = body.encode(os);
+		codeLength += sublength;
+		codeLength += BerLength.encodeLength(os, sublength);
+		// write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+		os.write(0xA1);
+		codeLength += 1;
+		
+		codeLength += hdr.encode(os, false);
+		// write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+		os.write(0xA0);
+		codeLength += 1;
+		
+		codeLength += BerLength.encodeLength(os, codeLength);
+
+		if (withTag) {
+			codeLength += tag.encode(os);
+		}
+
+		return codeLength;
+
+	}
+
+	public int decode(InputStream is) throws IOException {
+		return decode(is, true);
+	}
+
+	public int decode(InputStream is, boolean withTag) throws IOException {
+		int codeLength = 0;
+		int subCodeLength = 0;
+		BerTag berTag = new BerTag();
+
+		if (withTag) {
+			codeLength += tag.decodeAndCheck(is);
+		}
+
+		BerLength length = new BerLength();
+		codeLength += length.decode(is);
+
+		int totalLength = length.val;
+		codeLength += totalLength;
+
+		subCodeLength += berTag.decode(is);
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+			hdr = new XrancPduHdr();
+			subCodeLength += hdr.decode(is, false);
+			subCodeLength += berTag.decode(is);
+		}
+		else {
+			throw new IOException("Tag does not match the mandatory sequence element tag.");
+		}
+		
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+			subCodeLength += length.decode(is);
+			body = new XrancPduBody();
+			subCodeLength += body.decode(is, null);
+			if (subCodeLength == totalLength) {
+				return codeLength;
+			}
+		}
+		throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+		
+	}
+
+	public void encodeAndSave(int encodingSizeGuess) throws IOException {
+		BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+		encode(os, false);
+		code = os.getArray();
+	}
+
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		appendAsString(sb, 0);
+		return sb.toString();
+	}
+
+	public void appendAsString(StringBuilder sb, int indentLevel) {
+
+		sb.append("{");
+		sb.append("\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (hdr != null) {
+			sb.append("hdr: ");
+			hdr.appendAsString(sb, indentLevel + 1);
+		}
+		else {
+			sb.append("hdr: <empty-required-field>");
+		}
+		
+		sb.append(",\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (body != null) {
+			sb.append("body: ");
+			body.appendAsString(sb, indentLevel + 1);
+		}
+		else {
+			sb.append("body: <empty-required-field>");
+		}
+		
+		sb.append("\n");
+		for (int i = 0; i < indentLevel; i++) {
+			sb.append("\t");
+		}
+		sb.append("}");
+	}
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduBody.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduBody.java
new file mode 100644
index 0000000..047827e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduBody.java
@@ -0,0 +1,1099 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class XrancPduBody implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public byte[] code = null;
+	private CellConfigRequest cellConfigRequest = null;
+	private CellConfigReport cellConfigReport = null;
+	private UEAdmissionRequest uEAdmissionRequest = null;
+	private UEAdmissionResponse uEAdmissionResponse = null;
+	private UEAdmissionStatus uEAdmissionStatus = null;
+	private UEContextUpdate uEContextUpdate = null;
+	private UEReconfigInd uEReconfigInd = null;
+	private UEReleaseInd uEReleaseInd = null;
+	private BearerAdmissionRequest bearerAdmissionRequest = null;
+	private BearerAdmissionResponse bearerAdmissionResponse = null;
+	private BearerAdmissionStatus bearerAdmissionStatus = null;
+	private BearerReleaseInd bearerReleaseInd = null;
+	private HORequest hORequest = null;
+	private HOFailure hOFailure = null;
+	private HOComplete hOComplete = null;
+	private RXSigMeasReport rXSigMeasReport = null;
+	private L2MeasConfig l2MeasConfig = null;
+	private RadioMeasReportPerUE radioMeasReportPerUE = null;
+	private RadioMeasReportPerCell radioMeasReportPerCell = null;
+	private SchedMeasReportPerUE schedMeasReportPerUE = null;
+	private SchedMeasReportPerCell schedMeasReportPerCell = null;
+	private PDCPMeasReportPerUe pDCPMeasReportPerUe = null;
+	private UECapabilityEnquiry uECapabilityEnquiry = null;
+	private UECapabilityInfo uECapabilityInfo = null;
+	private ScellAdd scellAdd = null;
+	private ScellAddStatus scellAddStatus = null;
+	private ScellDelete scellDelete = null;
+	private RRMConfig rRMConfig = null;
+	private RRMConfigStatus rRMConfigStatus = null;
+	private SeNBAdd seNBAdd = null;
+	private SeNBAddStatus seNBAddStatus = null;
+	private SeNBDelete seNBDelete = null;
+	private TrafficSplitConfig trafficSplitConfig = null;
+	private HOCause hOCause = null;
+	private RRCMeasConfig rRCMeasConfig = null;
+	
+	public XrancPduBody() {
+	}
+
+	public XrancPduBody(byte[] code) {
+		this.code = code;
+	}
+
+	public void setCellConfigRequest(CellConfigRequest cellConfigRequest) {
+		this.cellConfigRequest = cellConfigRequest;
+	}
+
+	public CellConfigRequest getCellConfigRequest() {
+		return cellConfigRequest;
+	}
+
+	public void setCellConfigReport(CellConfigReport cellConfigReport) {
+		this.cellConfigReport = cellConfigReport;
+	}
+
+	public CellConfigReport getCellConfigReport() {
+		return cellConfigReport;
+	}
+
+	public void setUEAdmissionRequest(UEAdmissionRequest uEAdmissionRequest) {
+		this.uEAdmissionRequest = uEAdmissionRequest;
+	}
+
+	public UEAdmissionRequest getUEAdmissionRequest() {
+		return uEAdmissionRequest;
+	}
+
+	public void setUEAdmissionResponse(UEAdmissionResponse uEAdmissionResponse) {
+		this.uEAdmissionResponse = uEAdmissionResponse;
+	}
+
+	public UEAdmissionResponse getUEAdmissionResponse() {
+		return uEAdmissionResponse;
+	}
+
+	public void setUEAdmissionStatus(UEAdmissionStatus uEAdmissionStatus) {
+		this.uEAdmissionStatus = uEAdmissionStatus;
+	}
+
+	public UEAdmissionStatus getUEAdmissionStatus() {
+		return uEAdmissionStatus;
+	}
+
+	public void setUEContextUpdate(UEContextUpdate uEContextUpdate) {
+		this.uEContextUpdate = uEContextUpdate;
+	}
+
+	public UEContextUpdate getUEContextUpdate() {
+		return uEContextUpdate;
+	}
+
+	public void setUEReconfigInd(UEReconfigInd uEReconfigInd) {
+		this.uEReconfigInd = uEReconfigInd;
+	}
+
+	public UEReconfigInd getUEReconfigInd() {
+		return uEReconfigInd;
+	}
+
+	public void setUEReleaseInd(UEReleaseInd uEReleaseInd) {
+		this.uEReleaseInd = uEReleaseInd;
+	}
+
+	public UEReleaseInd getUEReleaseInd() {
+		return uEReleaseInd;
+	}
+
+	public void setBearerAdmissionRequest(BearerAdmissionRequest bearerAdmissionRequest) {
+		this.bearerAdmissionRequest = bearerAdmissionRequest;
+	}
+
+	public BearerAdmissionRequest getBearerAdmissionRequest() {
+		return bearerAdmissionRequest;
+	}
+
+	public void setBearerAdmissionResponse(BearerAdmissionResponse bearerAdmissionResponse) {
+		this.bearerAdmissionResponse = bearerAdmissionResponse;
+	}
+
+	public BearerAdmissionResponse getBearerAdmissionResponse() {
+		return bearerAdmissionResponse;
+	}
+
+	public void setBearerAdmissionStatus(BearerAdmissionStatus bearerAdmissionStatus) {
+		this.bearerAdmissionStatus = bearerAdmissionStatus;
+	}
+
+	public BearerAdmissionStatus getBearerAdmissionStatus() {
+		return bearerAdmissionStatus;
+	}
+
+	public void setBearerReleaseInd(BearerReleaseInd bearerReleaseInd) {
+		this.bearerReleaseInd = bearerReleaseInd;
+	}
+
+	public BearerReleaseInd getBearerReleaseInd() {
+		return bearerReleaseInd;
+	}
+
+	public void setHORequest(HORequest hORequest) {
+		this.hORequest = hORequest;
+	}
+
+	public HORequest getHORequest() {
+		return hORequest;
+	}
+
+	public void setHOFailure(HOFailure hOFailure) {
+		this.hOFailure = hOFailure;
+	}
+
+	public HOFailure getHOFailure() {
+		return hOFailure;
+	}
+
+	public void setHOComplete(HOComplete hOComplete) {
+		this.hOComplete = hOComplete;
+	}
+
+	public HOComplete getHOComplete() {
+		return hOComplete;
+	}
+
+	public void setRXSigMeasReport(RXSigMeasReport rXSigMeasReport) {
+		this.rXSigMeasReport = rXSigMeasReport;
+	}
+
+	public RXSigMeasReport getRXSigMeasReport() {
+		return rXSigMeasReport;
+	}
+
+	public void setL2MeasConfig(L2MeasConfig l2MeasConfig) {
+		this.l2MeasConfig = l2MeasConfig;
+	}
+
+	public L2MeasConfig getL2MeasConfig() {
+		return l2MeasConfig;
+	}
+
+	public void setRadioMeasReportPerUE(RadioMeasReportPerUE radioMeasReportPerUE) {
+		this.radioMeasReportPerUE = radioMeasReportPerUE;
+	}
+
+	public RadioMeasReportPerUE getRadioMeasReportPerUE() {
+		return radioMeasReportPerUE;
+	}
+
+	public void setRadioMeasReportPerCell(RadioMeasReportPerCell radioMeasReportPerCell) {
+		this.radioMeasReportPerCell = radioMeasReportPerCell;
+	}
+
+	public RadioMeasReportPerCell getRadioMeasReportPerCell() {
+		return radioMeasReportPerCell;
+	}
+
+	public void setSchedMeasReportPerUE(SchedMeasReportPerUE schedMeasReportPerUE) {
+		this.schedMeasReportPerUE = schedMeasReportPerUE;
+	}
+
+	public SchedMeasReportPerUE getSchedMeasReportPerUE() {
+		return schedMeasReportPerUE;
+	}
+
+	public void setSchedMeasReportPerCell(SchedMeasReportPerCell schedMeasReportPerCell) {
+		this.schedMeasReportPerCell = schedMeasReportPerCell;
+	}
+
+	public SchedMeasReportPerCell getSchedMeasReportPerCell() {
+		return schedMeasReportPerCell;
+	}
+
+	public void setPDCPMeasReportPerUe(PDCPMeasReportPerUe pDCPMeasReportPerUe) {
+		this.pDCPMeasReportPerUe = pDCPMeasReportPerUe;
+	}
+
+	public PDCPMeasReportPerUe getPDCPMeasReportPerUe() {
+		return pDCPMeasReportPerUe;
+	}
+
+	public void setUECapabilityEnquiry(UECapabilityEnquiry uECapabilityEnquiry) {
+		this.uECapabilityEnquiry = uECapabilityEnquiry;
+	}
+
+	public UECapabilityEnquiry getUECapabilityEnquiry() {
+		return uECapabilityEnquiry;
+	}
+
+	public void setUECapabilityInfo(UECapabilityInfo uECapabilityInfo) {
+		this.uECapabilityInfo = uECapabilityInfo;
+	}
+
+	public UECapabilityInfo getUECapabilityInfo() {
+		return uECapabilityInfo;
+	}
+
+	public void setScellAdd(ScellAdd scellAdd) {
+		this.scellAdd = scellAdd;
+	}
+
+	public ScellAdd getScellAdd() {
+		return scellAdd;
+	}
+
+	public void setScellAddStatus(ScellAddStatus scellAddStatus) {
+		this.scellAddStatus = scellAddStatus;
+	}
+
+	public ScellAddStatus getScellAddStatus() {
+		return scellAddStatus;
+	}
+
+	public void setScellDelete(ScellDelete scellDelete) {
+		this.scellDelete = scellDelete;
+	}
+
+	public ScellDelete getScellDelete() {
+		return scellDelete;
+	}
+
+	public void setRRMConfig(RRMConfig rRMConfig) {
+		this.rRMConfig = rRMConfig;
+	}
+
+	public RRMConfig getRRMConfig() {
+		return rRMConfig;
+	}
+
+	public void setRRMConfigStatus(RRMConfigStatus rRMConfigStatus) {
+		this.rRMConfigStatus = rRMConfigStatus;
+	}
+
+	public RRMConfigStatus getRRMConfigStatus() {
+		return rRMConfigStatus;
+	}
+
+	public void setSeNBAdd(SeNBAdd seNBAdd) {
+		this.seNBAdd = seNBAdd;
+	}
+
+	public SeNBAdd getSeNBAdd() {
+		return seNBAdd;
+	}
+
+	public void setSeNBAddStatus(SeNBAddStatus seNBAddStatus) {
+		this.seNBAddStatus = seNBAddStatus;
+	}
+
+	public SeNBAddStatus getSeNBAddStatus() {
+		return seNBAddStatus;
+	}
+
+	public void setSeNBDelete(SeNBDelete seNBDelete) {
+		this.seNBDelete = seNBDelete;
+	}
+
+	public SeNBDelete getSeNBDelete() {
+		return seNBDelete;
+	}
+
+	public void setTrafficSplitConfig(TrafficSplitConfig trafficSplitConfig) {
+		this.trafficSplitConfig = trafficSplitConfig;
+	}
+
+	public TrafficSplitConfig getTrafficSplitConfig() {
+		return trafficSplitConfig;
+	}
+
+	public void setHOCause(HOCause hOCause) {
+		this.hOCause = hOCause;
+	}
+
+	public HOCause getHOCause() {
+		return hOCause;
+	}
+
+	public void setRRCMeasConfig(RRCMeasConfig rRCMeasConfig) {
+		this.rRCMeasConfig = rRCMeasConfig;
+	}
+
+	public RRCMeasConfig getRRCMeasConfig() {
+		return rRCMeasConfig;
+	}
+
+	public int encode(BerByteArrayOutputStream os) throws IOException {
+
+		if (code != null) {
+			for (int i = code.length - 1; i >= 0; i--) {
+				os.write(code[i]);
+			}
+			return code.length;
+		}
+
+		int codeLength = 0;
+		if (rRCMeasConfig != null) {
+			codeLength += rRCMeasConfig.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 34
+			os.write(0x22);
+			os.write(0xBF);
+			codeLength += 2;
+			return codeLength;
+		}
+		
+		if (hOCause != null) {
+			codeLength += hOCause.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 33
+			os.write(0x21);
+			os.write(0xBF);
+			codeLength += 2;
+			return codeLength;
+		}
+		
+		if (trafficSplitConfig != null) {
+			codeLength += trafficSplitConfig.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 32
+			os.write(0x20);
+			os.write(0xBF);
+			codeLength += 2;
+			return codeLength;
+		}
+		
+		if (seNBDelete != null) {
+			codeLength += seNBDelete.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 31
+			os.write(0x1F);
+			os.write(0xBF);
+			codeLength += 2;
+			return codeLength;
+		}
+		
+		if (seNBAddStatus != null) {
+			codeLength += seNBAddStatus.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 30
+			os.write(0xBE);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (seNBAdd != null) {
+			codeLength += seNBAdd.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 29
+			os.write(0xBD);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (rRMConfigStatus != null) {
+			codeLength += rRMConfigStatus.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 28
+			os.write(0xBC);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (rRMConfig != null) {
+			codeLength += rRMConfig.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 27
+			os.write(0xBB);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (scellDelete != null) {
+			codeLength += scellDelete.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 26
+			os.write(0xBA);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (scellAddStatus != null) {
+			codeLength += scellAddStatus.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 25
+			os.write(0xB9);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (scellAdd != null) {
+			codeLength += scellAdd.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 24
+			os.write(0xB8);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uECapabilityInfo != null) {
+			codeLength += uECapabilityInfo.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 23
+			os.write(0xB7);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uECapabilityEnquiry != null) {
+			codeLength += uECapabilityEnquiry.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 22
+			os.write(0xB6);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (pDCPMeasReportPerUe != null) {
+			codeLength += pDCPMeasReportPerUe.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 21
+			os.write(0xB5);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (schedMeasReportPerCell != null) {
+			codeLength += schedMeasReportPerCell.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 20
+			os.write(0xB4);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (schedMeasReportPerUE != null) {
+			codeLength += schedMeasReportPerUE.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 19
+			os.write(0xB3);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (radioMeasReportPerCell != null) {
+			codeLength += radioMeasReportPerCell.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 18
+			os.write(0xB2);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (radioMeasReportPerUE != null) {
+			codeLength += radioMeasReportPerUE.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 17
+			os.write(0xB1);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (l2MeasConfig != null) {
+			codeLength += l2MeasConfig.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 16
+			os.write(0xB0);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (rXSigMeasReport != null) {
+			codeLength += rXSigMeasReport.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 15
+			os.write(0xAF);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (hOComplete != null) {
+			codeLength += hOComplete.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 14
+			os.write(0xAE);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (hOFailure != null) {
+			codeLength += hOFailure.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 13
+			os.write(0xAD);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (hORequest != null) {
+			codeLength += hORequest.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 12
+			os.write(0xAC);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (bearerReleaseInd != null) {
+			codeLength += bearerReleaseInd.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 11
+			os.write(0xAB);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (bearerAdmissionStatus != null) {
+			codeLength += bearerAdmissionStatus.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 10
+			os.write(0xAA);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (bearerAdmissionResponse != null) {
+			codeLength += bearerAdmissionResponse.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 9
+			os.write(0xA9);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (bearerAdmissionRequest != null) {
+			codeLength += bearerAdmissionRequest.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 8
+			os.write(0xA8);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEReleaseInd != null) {
+			codeLength += uEReleaseInd.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 7
+			os.write(0xA7);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEReconfigInd != null) {
+			codeLength += uEReconfigInd.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 6
+			os.write(0xA6);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEContextUpdate != null) {
+			codeLength += uEContextUpdate.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 5
+			os.write(0xA5);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEAdmissionStatus != null) {
+			codeLength += uEAdmissionStatus.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 4
+			os.write(0xA4);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEAdmissionResponse != null) {
+			codeLength += uEAdmissionResponse.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 3
+			os.write(0xA3);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (uEAdmissionRequest != null) {
+			codeLength += uEAdmissionRequest.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 2
+			os.write(0xA2);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (cellConfigReport != null) {
+			codeLength += cellConfigReport.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 1
+			os.write(0xA1);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		if (cellConfigRequest != null) {
+			codeLength += cellConfigRequest.encode(os, false);
+			// write tag: CONTEXT_CLASS, CONSTRUCTED, 0
+			os.write(0xA0);
+			codeLength += 1;
+			return codeLength;
+		}
+		
+		throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
+	}
+
+	public int decode(InputStream is) throws IOException {
+		return decode(is, null);
+	}
+
+	public int decode(InputStream is, BerTag berTag) throws IOException {
+
+		int codeLength = 0;
+		BerTag passedTag = berTag;
+
+		if (berTag == null) {
+			berTag = new BerTag();
+			codeLength += berTag.decode(is);
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
+			cellConfigRequest = new CellConfigRequest();
+			codeLength += cellConfigRequest.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
+			cellConfigReport = new CellConfigReport();
+			codeLength += cellConfigReport.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
+			uEAdmissionRequest = new UEAdmissionRequest();
+			codeLength += uEAdmissionRequest.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
+			uEAdmissionResponse = new UEAdmissionResponse();
+			codeLength += uEAdmissionResponse.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
+			uEAdmissionStatus = new UEAdmissionStatus();
+			codeLength += uEAdmissionStatus.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
+			uEContextUpdate = new UEContextUpdate();
+			codeLength += uEContextUpdate.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) {
+			uEReconfigInd = new UEReconfigInd();
+			codeLength += uEReconfigInd.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) {
+			uEReleaseInd = new UEReleaseInd();
+			codeLength += uEReleaseInd.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
+			bearerAdmissionRequest = new BearerAdmissionRequest();
+			codeLength += bearerAdmissionRequest.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
+			bearerAdmissionResponse = new BearerAdmissionResponse();
+			codeLength += bearerAdmissionResponse.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
+			bearerAdmissionStatus = new BearerAdmissionStatus();
+			codeLength += bearerAdmissionStatus.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 11)) {
+			bearerReleaseInd = new BearerReleaseInd();
+			codeLength += bearerReleaseInd.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 12)) {
+			hORequest = new HORequest();
+			codeLength += hORequest.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 13)) {
+			hOFailure = new HOFailure();
+			codeLength += hOFailure.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 14)) {
+			hOComplete = new HOComplete();
+			codeLength += hOComplete.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 15)) {
+			rXSigMeasReport = new RXSigMeasReport();
+			codeLength += rXSigMeasReport.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 16)) {
+			l2MeasConfig = new L2MeasConfig();
+			codeLength += l2MeasConfig.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 17)) {
+			radioMeasReportPerUE = new RadioMeasReportPerUE();
+			codeLength += radioMeasReportPerUE.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 18)) {
+			radioMeasReportPerCell = new RadioMeasReportPerCell();
+			codeLength += radioMeasReportPerCell.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 19)) {
+			schedMeasReportPerUE = new SchedMeasReportPerUE();
+			codeLength += schedMeasReportPerUE.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 20)) {
+			schedMeasReportPerCell = new SchedMeasReportPerCell();
+			codeLength += schedMeasReportPerCell.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 21)) {
+			pDCPMeasReportPerUe = new PDCPMeasReportPerUe();
+			codeLength += pDCPMeasReportPerUe.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 22)) {
+			uECapabilityEnquiry = new UECapabilityEnquiry();
+			codeLength += uECapabilityEnquiry.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 23)) {
+			uECapabilityInfo = new UECapabilityInfo();
+			codeLength += uECapabilityInfo.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 24)) {
+			scellAdd = new ScellAdd();
+			codeLength += scellAdd.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 25)) {
+			scellAddStatus = new ScellAddStatus();
+			codeLength += scellAddStatus.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 26)) {
+			scellDelete = new ScellDelete();
+			codeLength += scellDelete.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 27)) {
+			rRMConfig = new RRMConfig();
+			codeLength += rRMConfig.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 28)) {
+			rRMConfigStatus = new RRMConfigStatus();
+			codeLength += rRMConfigStatus.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 29)) {
+			seNBAdd = new SeNBAdd();
+			codeLength += seNBAdd.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 30)) {
+			seNBAddStatus = new SeNBAddStatus();
+			codeLength += seNBAddStatus.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 31)) {
+			seNBDelete = new SeNBDelete();
+			codeLength += seNBDelete.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 32)) {
+			trafficSplitConfig = new TrafficSplitConfig();
+			codeLength += trafficSplitConfig.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 33)) {
+			hOCause = new HOCause();
+			codeLength += hOCause.decode(is, false);
+			return codeLength;
+		}
+
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 34)) {
+			rRCMeasConfig = new RRCMeasConfig();
+			codeLength += rRCMeasConfig.decode(is, false);
+			return codeLength;
+		}
+
+		if (passedTag != null) {
+			return 0;
+		}
+
+		throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
+	}
+
+	public void encodeAndSave(int encodingSizeGuess) throws IOException {
+		BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+		encode(os);
+		code = os.getArray();
+	}
+
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		appendAsString(sb, 0);
+		return sb.toString();
+	}
+
+	public void appendAsString(StringBuilder sb, int indentLevel) {
+
+		if (cellConfigRequest != null) {
+			sb.append("cellConfigRequest: ");
+			cellConfigRequest.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (cellConfigReport != null) {
+			sb.append("cellConfigReport: ");
+			cellConfigReport.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEAdmissionRequest != null) {
+			sb.append("uEAdmissionRequest: ");
+			uEAdmissionRequest.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEAdmissionResponse != null) {
+			sb.append("uEAdmissionResponse: ");
+			uEAdmissionResponse.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEAdmissionStatus != null) {
+			sb.append("uEAdmissionStatus: ");
+			uEAdmissionStatus.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEContextUpdate != null) {
+			sb.append("uEContextUpdate: ");
+			uEContextUpdate.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEReconfigInd != null) {
+			sb.append("uEReconfigInd: ");
+			uEReconfigInd.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uEReleaseInd != null) {
+			sb.append("uEReleaseInd: ");
+			uEReleaseInd.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (bearerAdmissionRequest != null) {
+			sb.append("bearerAdmissionRequest: ");
+			bearerAdmissionRequest.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (bearerAdmissionResponse != null) {
+			sb.append("bearerAdmissionResponse: ");
+			bearerAdmissionResponse.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (bearerAdmissionStatus != null) {
+			sb.append("bearerAdmissionStatus: ");
+			bearerAdmissionStatus.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (bearerReleaseInd != null) {
+			sb.append("bearerReleaseInd: ");
+			bearerReleaseInd.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (hORequest != null) {
+			sb.append("hORequest: ");
+			hORequest.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (hOFailure != null) {
+			sb.append("hOFailure: ");
+			hOFailure.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (hOComplete != null) {
+			sb.append("hOComplete: ");
+			hOComplete.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (rXSigMeasReport != null) {
+			sb.append("rXSigMeasReport: ");
+			rXSigMeasReport.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (l2MeasConfig != null) {
+			sb.append("l2MeasConfig: ");
+			l2MeasConfig.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (radioMeasReportPerUE != null) {
+			sb.append("radioMeasReportPerUE: ");
+			radioMeasReportPerUE.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (radioMeasReportPerCell != null) {
+			sb.append("radioMeasReportPerCell: ");
+			radioMeasReportPerCell.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (schedMeasReportPerUE != null) {
+			sb.append("schedMeasReportPerUE: ");
+			schedMeasReportPerUE.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (schedMeasReportPerCell != null) {
+			sb.append("schedMeasReportPerCell: ");
+			schedMeasReportPerCell.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (pDCPMeasReportPerUe != null) {
+			sb.append("pDCPMeasReportPerUe: ");
+			pDCPMeasReportPerUe.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uECapabilityEnquiry != null) {
+			sb.append("uECapabilityEnquiry: ");
+			uECapabilityEnquiry.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (uECapabilityInfo != null) {
+			sb.append("uECapabilityInfo: ");
+			uECapabilityInfo.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (scellAdd != null) {
+			sb.append("scellAdd: ");
+			scellAdd.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (scellAddStatus != null) {
+			sb.append("scellAddStatus: ");
+			scellAddStatus.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (scellDelete != null) {
+			sb.append("scellDelete: ");
+			scellDelete.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (rRMConfig != null) {
+			sb.append("rRMConfig: ");
+			rRMConfig.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (rRMConfigStatus != null) {
+			sb.append("rRMConfigStatus: ");
+			rRMConfigStatus.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (seNBAdd != null) {
+			sb.append("seNBAdd: ");
+			seNBAdd.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (seNBAddStatus != null) {
+			sb.append("seNBAddStatus: ");
+			seNBAddStatus.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (seNBDelete != null) {
+			sb.append("seNBDelete: ");
+			seNBDelete.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (trafficSplitConfig != null) {
+			sb.append("trafficSplitConfig: ");
+			trafficSplitConfig.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (hOCause != null) {
+			sb.append("hOCause: ");
+			hOCause.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		if (rRCMeasConfig != null) {
+			sb.append("rRCMeasConfig: ");
+			rRCMeasConfig.appendAsString(sb, indentLevel + 1);
+			return;
+		}
+
+		sb.append("<none>");
+	}
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduHdr.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduHdr.java
new file mode 100644
index 0000000..49390fe
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/pdu/XrancPduHdr.java
@@ -0,0 +1,173 @@
+/**
+ * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
+ */
+
+package org.onosproject.xran.asn1lib.pdu;
+
+
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.BerLength;
+import org.onosproject.xran.asn1lib.ber.BerTag;
+import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+public class XrancPduHdr implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
+
+	public byte[] code = null;
+	private BerUTF8String ver = null;
+	private XrancApiID apiId = null;
+	
+	public XrancPduHdr() {
+	}
+
+	public XrancPduHdr(byte[] code) {
+		this.code = code;
+	}
+
+	public void setVer(BerUTF8String ver) {
+		this.ver = ver;
+	}
+
+	public BerUTF8String getVer() {
+		return ver;
+	}
+
+	public void setApiId(XrancApiID apiId) {
+		this.apiId = apiId;
+	}
+
+	public XrancApiID getApiId() {
+		return apiId;
+	}
+
+	public int encode(BerByteArrayOutputStream os) throws IOException {
+		return encode(os, true);
+	}
+
+	public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
+
+		if (code != null) {
+			for (int i = code.length - 1; i >= 0; i--) {
+				os.write(code[i]);
+			}
+			if (withTag) {
+				return tag.encode(os) + code.length;
+			}
+			return code.length;
+		}
+
+		int codeLength = 0;
+		codeLength += apiId.encode(os, false);
+		// write tag: CONTEXT_CLASS, PRIMITIVE, 1
+		os.write(0x81);
+		codeLength += 1;
+		
+		codeLength += ver.encode(os, false);
+		// write tag: CONTEXT_CLASS, PRIMITIVE, 0
+		os.write(0x80);
+		codeLength += 1;
+		
+		codeLength += BerLength.encodeLength(os, codeLength);
+
+		if (withTag) {
+			codeLength += tag.encode(os);
+		}
+
+		return codeLength;
+
+	}
+
+	public int decode(InputStream is) throws IOException {
+		return decode(is, true);
+	}
+
+	public int decode(InputStream is, boolean withTag) throws IOException {
+		int codeLength = 0;
+		int subCodeLength = 0;
+		BerTag berTag = new BerTag();
+
+		if (withTag) {
+			codeLength += tag.decodeAndCheck(is);
+		}
+
+		BerLength length = new BerLength();
+		codeLength += length.decode(is);
+
+		int totalLength = length.val;
+		codeLength += totalLength;
+
+		subCodeLength += berTag.decode(is);
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
+			ver = new BerUTF8String();
+			subCodeLength += ver.decode(is, false);
+			subCodeLength += berTag.decode(is);
+		}
+		else {
+			throw new IOException("Tag does not match the mandatory sequence element tag.");
+		}
+		
+		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
+			apiId = new XrancApiID();
+			subCodeLength += apiId.decode(is, false);
+			if (subCodeLength == totalLength) {
+				return codeLength;
+			}
+		}
+		throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
+
+		
+	}
+
+	public void encodeAndSave(int encodingSizeGuess) throws IOException {
+		BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
+		encode(os, false);
+		code = os.getArray();
+	}
+
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		appendAsString(sb, 0);
+		return sb.toString();
+	}
+
+	public void appendAsString(StringBuilder sb, int indentLevel) {
+
+		sb.append("{");
+		sb.append("\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (ver != null) {
+			sb.append("ver: ").append(ver);
+		}
+		else {
+			sb.append("ver: <empty-required-field>");
+		}
+		
+		sb.append(",\n");
+		for (int i = 0; i < indentLevel + 1; i++) {
+			sb.append("\t");
+		}
+		if (apiId != null) {
+			sb.append("apiId: ").append(apiId);
+		}
+		else {
+			sb.append("apiId: <empty-required-field>");
+		}
+		
+		sb.append("\n");
+		for (int i = 0; i < indentLevel; i++) {
+			sb.append("\t");
+		}
+		sb.append("}");
+	}
+
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/asn1lib/util/HexConverter.java b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/util/HexConverter.java
new file mode 100644
index 0000000..573598f
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/asn1lib/util/HexConverter.java
@@ -0,0 +1,155 @@
+package org.onosproject.xran.asn1lib.util;
+
+public class HexConverter {
+
+    public static String toHexString(byte b) {
+        StringBuilder builder = new StringBuilder();
+        appendHexString(b, builder);
+        return builder.toString();
+    }
+
+    public static String toHexString(byte[] bytes) {
+        return toHexString(bytes, 0, bytes.length);
+    }
+
+    public static String toHexString(byte[] bytes, int offset, int length) {
+        StringBuilder builder = new StringBuilder();
+
+        int l = 1;
+        for (int i = offset; i < (offset + length); i++) {
+            if ((l != 1) && ((l - 1) % 8 == 0)) {
+                builder.append(' ');
+            }
+            if ((l != 1) && ((l - 1) % 16 == 0)) {
+                builder.append('\n');
+            }
+            l++;
+            appendHexString(bytes[i], builder);
+            if (i != offset + length - 1) {
+                builder.append(' ');
+            }
+        }
+
+        return builder.toString();
+    }
+
+    /**
+     * Returns the integer value as hex string filled with leading zeros. If you do not want leading zeros use
+     * Integer.toHexString(int i) instead.
+     * 
+     * @param i
+     *            the integer value to be converted
+     * @return the hex string
+     */
+    public static String toShortHexString(int i) {
+        byte[] bytes = new byte[] { (byte) (i >> 24), (byte) (i >> 16), (byte) (i >> 8), (byte) (i) };
+        return toShortHexString(bytes);
+    }
+
+    /**
+     * Returns the long value as hex string filled with leading zeros. If you do not want leading zeros use
+     * Long.toHexString(long i) instead.
+     * 
+     * @param l
+     *            the long value to be converted
+     * @return the hex string
+     */
+    public static String toShortHexString(long l) {
+        byte[] bytes = new byte[] { (byte) (l >> 56), (byte) (l >> 48), (byte) (l >> 40), (byte) (l >> 32),
+                (byte) (l >> 24), (byte) (l >> 16), (byte) (l >> 8), (byte) (l) };
+        return toShortHexString(bytes);
+    }
+
+    /**
+     * Returns the byte as a hex string. If b is less than 16 the hex string returned contains a leading zero.
+     * 
+     * @param b
+     *            the byte to be converted
+     * @return the byte as a hex string.
+     */
+    public static String toShortHexString(byte b) {
+        return toShortHexString(new byte[] { b });
+    }
+
+    private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
+
+    public static String toShortHexString(byte[] bytes) {
+        return toShortHexString(bytes, 0, bytes.length);
+    }
+
+    public static String toShortHexString(byte[] bytes, int offset, int length) {
+        char[] hexChars = new char[length * 2];
+        for (int j = offset; j < (offset + length); j++) {
+            int v = bytes[j] & 0xff;
+            hexChars[j * 2] = hexArray[v >>> 4];
+            hexChars[j * 2 + 1] = hexArray[v & 0x0f];
+        }
+        return new String(hexChars);
+    }
+
+    public static byte[] fromShortHexString(String shortHexString) throws NumberFormatException {
+
+        validate(shortHexString);
+
+        int length = shortHexString.length();
+
+        byte[] data = new byte[length / 2];
+        for (int i = 0; i < length; i += 2) {
+            int firstCharacter = Character.digit(shortHexString.charAt(i), 16);
+            int secondCharacter = Character.digit(shortHexString.charAt(i + 1), 16);
+
+            if (firstCharacter == -1 || secondCharacter == -1) {
+                throw new NumberFormatException("string is not a legal hex string.");
+            }
+
+            data[i / 2] = (byte) ((firstCharacter << 4) + secondCharacter);
+        }
+        return data;
+    }
+
+    public static void appendShortHexString(byte b, StringBuilder builder) {
+        builder.append(toShortHexString(b));
+    }
+
+    public static void appendShortHexString(StringBuilder builder, byte[] bytes, int offset, int length) {
+        builder.append(toShortHexString(bytes, offset, length));
+    }
+
+    public static void appendHexString(byte b, StringBuilder builder) {
+        builder.append("0x");
+        appendShortHexString(b, builder);
+    }
+
+    public static void appendHexString(StringBuilder builder, byte[] byteArray, int offset, int length) {
+        int l = 1;
+        for (int i = offset; i < (offset + length); i++) {
+            if ((l != 1) && ((l - 1) % 8 == 0)) {
+                builder.append(' ');
+            }
+            if ((l != 1) && ((l - 1) % 16 == 0)) {
+                builder.append('\n');
+            }
+            l++;
+            appendHexString(byteArray[i], builder);
+            if (i != offset + length - 1) {
+                builder.append(' ');
+            }
+        }
+    }
+
+    private static void validate(String s) {
+        if (s == null) {
+            throw new IllegalArgumentException("string s may not be null");
+        }
+
+        if ((s.length() == 0) || ((s.length() % 2) != 0)) {
+            throw new NumberFormatException("string is not a legal hex string.");
+        }
+    }
+
+    /**
+     * Don't let anyone instantiate this class.
+     */
+    private HexConverter() {
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/DefaultXranStore.java b/apps/xran/src/main/java/org.onosproject.xran/impl/DefaultXranStore.java
new file mode 100644
index 0000000..14b93af
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/DefaultXranStore.java
@@ -0,0 +1,454 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Lists;
+import io.netty.channel.ChannelHandlerContext;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranStore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibLink;
+import org.onosproject.xran.impl.entities.RnibSlice;
+import org.onosproject.xran.impl.entities.RnibUe;
+import org.onosproject.xran.impl.identifiers.EcgiCrntiPair;
+import org.onosproject.xran.impl.identifiers.LinkId;
+import org.slf4j.Logger;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Default xran store.
+ */
+@Component(immediate = true)
+@Service
+public class DefaultXranStore extends AbstractStore implements XranStore {
+    private static final String XRAN_APP_ID = "org.onosproject.xran";
+
+    private final Logger log = getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    protected ConcurrentMap<LinkId, RnibLink> linkMap = new ConcurrentHashMap<>();
+    private ConcurrentMap<ECGI, RnibCell> cellMap = new ConcurrentHashMap<>();
+    private ConcurrentMap<Long, RnibUe> ueMap = new ConcurrentHashMap<>();
+    private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>();
+
+    private XranService controller;
+    private IdGenerator ueIdGenerator;
+
+    // map to get the context channel based on ecgi
+    private ConcurrentMap<ECGI, ChannelHandlerContext> ctxMap = new ConcurrentHashMap<>();
+    // pci-arfcn to ecgi bimap
+    private BiMap<PCIARFCN, ECGI> pciarfcnMap = HashBiMap.create();
+    // ECGI, CRNTI pair of primary cell for specified UE.
+    private BiMap<EcgiCrntiPair, Long> crntiMap = HashBiMap.create();
+
+
+    @Activate
+    public void activate() {
+        ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
+
+        // create ue id generator
+        ueIdGenerator = coreService.getIdGenerator("xran-ue-id");
+
+        log.info("XRAN Default Store Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        linkMap.clear();
+        cellMap.clear();
+        ueMap.clear();
+        sliceMap.clear();
+
+        controller = null;
+        ueIdGenerator = null;
+
+        log.info("XRAN Default Store Stopped");
+    }
+
+    @Override
+    public List<RnibLink> getLinks() {
+        List<RnibLink> list = Lists.newArrayList();
+        list.addAll(linkMap.values());
+        return list;
+    }
+
+    @Override
+    public List<RnibLink> getLinks(ECGI ecgi) {
+        List<RnibLink> list = Lists.newArrayList();
+        list.addAll(
+                linkMap.keySet()
+                        .stream()
+                        .filter(k -> k.getEcgi().equals(ecgi))
+                        .map(v -> linkMap.get(v))
+                        .collect(Collectors.toList()));
+        return list;
+    }
+
+    @Override
+    public List<RnibLink> getLinks(String eciHex) {
+        List<RnibLink> list = Lists.newArrayList();
+        EUTRANCellIdentifier eci = hexToEci(eciHex);
+
+        list.addAll(
+                linkMap.keySet()
+                        .stream()
+                        .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
+                        .map(v -> linkMap.get(v))
+                        .collect(Collectors.toList()));
+
+        return list;
+    }
+
+    @Override
+    public List<RnibLink> getLinks(long euId) {
+        List<RnibLink> list = Lists.newArrayList();
+
+        list.addAll(
+                linkMap.keySet()
+                        .stream()
+                        .filter(k -> k.getUeId().equals(euId))
+                        .map(v -> linkMap.get(v))
+                        .collect(Collectors.toList()));
+
+        return list;
+    }
+
+
+    @Override
+    public Optional<RnibLink> getLink(String eciHex, long euId) {
+        EUTRANCellIdentifier eci = hexToEci(eciHex);
+
+        Optional<LinkId> first = linkMap.keySet()
+                .stream()
+                .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci) &&
+                        linkId.getUeId().equals(euId))
+                .findFirst();
+
+        return first.map(linkId -> linkMap.get(linkId));
+    }
+
+    @Override
+    public void storeLink(RnibLink link) {
+        synchronized (this) {
+            if (link.getLinkId() != null) {
+                // if we add a primary link then change the primary to non serving
+                if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
+                    RnibUe ue = link.getLinkId().getUe();
+                    getLinks(ue.getId())
+                            .stream()
+                            .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
+                            .forEach(l -> l.setType(RnibLink.Type.NON_SERVING));
+                }
+                linkMap.put(link.getLinkId(), link);
+            }
+        }
+    }
+
+    @Override
+    public boolean removeLink(LinkId link) {
+        return linkMap.remove(link) != null;
+    }
+
+    @Override
+    public Optional<RnibLink> getLink(ECGI ecgi, Long ueId) {
+        LinkId linkId = LinkId.valueOf(ecgi, ueId);
+        return Optional.ofNullable(linkMap.get(linkId));
+    }
+
+    @Override
+    public Optional<RnibLink> getLink(ECGI src, CRNTI dst) {
+        return getUe(src, dst).flatMap(ue -> getLink(src, ue.getId()));
+    }
+
+    @Override
+    public void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf) {
+        link.modifyRrmParameters(rrmConf);
+    }
+
+    @Override
+    public List<Object> getNodes() {
+        List<Object> list = Lists.newArrayList();
+        list.addAll(cellMap.values());
+        list.addAll(ueMap.values());
+        return list;
+    }
+
+    @Override
+    public List<RnibCell> getCellNodes() {
+        List<RnibCell> list = Lists.newArrayList();
+        list.addAll(cellMap.values());
+        return list;
+    }
+
+    @Override
+    public List<RnibUe> getUeNodes() {
+        List<RnibUe> list = Lists.newArrayList();
+        list.addAll(ueMap.values());
+        return list;
+    }
+
+    @Override
+    public Optional<Object> getNode(String nodeId) {
+        try {
+            return Optional.ofNullable(getCell(nodeId));
+        } catch (Exception ignored) {
+        }
+        return Optional.ofNullable(getUe(Long.parseLong(nodeId)));
+    }
+
+    @Override
+    public void storeCell(RnibCell cell) {
+        if (cell.getEcgi() != null) {
+            cellMap.putIfAbsent(cell.getEcgi(), cell);
+        }
+    }
+
+    @Override
+    public boolean removeCell(ECGI ecgi) {
+        pciarfcnMap.inverse().remove(ecgi);
+        ctxMap.remove(ecgi);
+        return cellMap.remove(ecgi) != null;
+    }
+
+    @Override
+    public boolean removeCell(PCIARFCN pciarfcn) {
+        return removeCell(pciarfcnMap.get(pciarfcn));
+    }
+
+    @Override
+    public Optional<RnibCell> getCell(String hexeci) {
+        EUTRANCellIdentifier eci = hexToEci(hexeci);
+        Optional<ECGI> first = cellMap.keySet()
+                .stream()
+                .filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci))
+                .findFirst();
+        return first.map(ecgi -> cellMap.get(ecgi));
+    }
+
+    @Override
+    public Optional<RnibCell> getCell(ECGI ecgi) {
+        return Optional.ofNullable(cellMap.get(ecgi));
+    }
+
+    @Override
+    public Optional<RnibCell> getCell(PCIARFCN id) {
+        ECGI ecgi;
+        ecgi = pciarfcnMap.get(id);
+        return getCell(ecgi);
+    }
+
+    @Override
+    public void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) throws Exception {
+        List<RnibLink> linkList = getLinks(cell.getEcgi());
+        List<RnibUe> ueList = linkList.stream()
+                .map(link -> link.getLinkId().getUe())
+                .collect(Collectors.toList());
+
+        cell.modifyRrmConfig(rrmConf, ueList);
+    }
+
+    @Override
+    public Optional<RnibSlice> getSlice(long sliceId) {
+        return Optional.ofNullable(sliceMap.get(sliceId));
+    }
+
+    @Override
+    public boolean createSlice(ObjectNode attributes) {
+        return false;
+    }
+
+    @Override
+    public boolean removeCell(long sliceId) {
+        return sliceMap.remove(sliceId) != null;
+    }
+
+    @Override
+    public Optional<XranService> getController() {
+        return Optional.ofNullable(controller);
+    }
+
+    @Override
+    public void setController(XranService controller) {
+        this.controller = controller;
+    }
+
+    @Override
+    public void storeUe(RnibUe ue) {
+        long newId;
+        if (ue.getId() == null) {
+            newId = ueIdGenerator.getNewId();
+            ue.setId(newId);
+        } else {
+            newId = ue.getId();
+        }
+        ueMap.put(newId, ue);
+    }
+
+    @Override
+    public void storeUe(RnibCell cell, RnibUe ue) {
+        storeUe(ue);
+        storeCrnti(cell, ue);
+    }
+
+    @Override
+    public boolean removeUe(long ueId) {
+        log.info("removing ue {} {}", ueId, ueMap);
+        crntiMap.inverse().remove(ueId);
+        return ueMap.remove(ueId) != null;
+    }
+
+    @Override
+    public void storePciArfcn(RnibCell value) {
+        value.getOptConf().ifPresent(cfg -> {
+            PCIARFCN pciarfcn = new PCIARFCN();
+            pciarfcn.setPci(cfg.getPci());
+            pciarfcn.setEarfcnDl(cfg.getEarfcnDl());
+            pciarfcnMap.put(pciarfcn, value.getEcgi());
+        });
+    }
+
+    @Override
+    public void storeCtx(RnibCell value, ChannelHandlerContext ctx) {
+        if (value.getEcgi() != null) {
+            ctxMap.put(value.getEcgi(), ctx);
+            storeCell(value);
+        }
+    }
+
+    @Override
+    public Optional<ChannelHandlerContext> getCtx(ECGI ecgi) {
+        return Optional.ofNullable(ctxMap.get(ecgi));
+    }
+
+    @Override
+    public BiMap<EcgiCrntiPair, Long> getCrnti() {
+        return crntiMap;
+    }
+
+    @Override
+    public void storeCrnti(RnibCell cell, RnibUe ue) {
+        CRNTI crnti = ue.getCrnti();
+        ECGI ecgi = cell.getEcgi();
+
+        if (crnti != null && ecgi != null) {
+            // check if there is an ecgi, crnti pair for this UE id.
+            EcgiCrntiPair oldPair = crntiMap.inverse().get(ue.getId()),
+                    newPair = EcgiCrntiPair.valueOf(cell.getEcgi(), ue.getCrnti());
+
+            if (oldPair == null) {
+                crntiMap.put(newPair, ue.getId());
+            } else {
+                // remove old pair and add the new pair which corresponds to the primary cell.
+                crntiMap.inverse().remove(ue.getId());
+                crntiMap.put(newPair, ue.getId());
+            }
+        }
+    }
+
+    @Override
+    public void putPrimaryLink(RnibCell cell, RnibUe ue) {
+        RnibLink link = new RnibLink(cell, ue);
+        // set link to primary before storing
+        link.setType(RnibLink.Type.SERVING_PRIMARY);
+        storeLink(link);
+        storeCrnti(cell, ue);
+    }
+
+    @Override
+    public Optional<RnibLink> putNonServingLink(RnibCell cell, CRNTI crnti) {
+        return getUe(cell.getEcgi(), crnti).map(ue -> {
+            RnibLink link = new RnibLink(cell, ue);
+            storeLink(link);
+            return Optional.of(link);
+        }).orElse(Optional.empty());
+    }
+
+    @Override
+    public Optional<RnibLink> putNonServingLink(RnibCell cell, Long ueId) {
+        return getUe(ueId).map(ue -> {
+            RnibLink link = new RnibLink(cell, ue);
+            storeLink(link);
+            return Optional.of(link);
+        }).orElse(Optional.empty());
+    }
+
+    @Override
+    public Optional<CRNTI> getCrnti(Long ueId) {
+        return Optional.ofNullable(getCrnti().inverse().get(ueId).getValue());
+    }
+
+    @Override
+    public Optional<RnibCell> getPrimaryCell(RnibUe ue) {
+        // search all links for this UE and find PRIMARY.
+        Optional<RnibLink> primary = getLinks().stream()
+                .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
+                .filter(l -> l.getLinkId().getUe().equals(ue))
+                .findFirst();
+
+        return primary.flatMap(l -> Optional.of(l.getLinkId().getCell()));
+    }
+
+    @Override
+    public Optional<RnibUe> getUe(long ueId) {
+        return Optional.ofNullable(ueMap.get(ueId));
+    }
+
+    @Override
+    public Optional<RnibUe> getUe(ECGI ecgi, CRNTI crnti) {
+        return Optional.ofNullable(crntiMap.get(EcgiCrntiPair.valueOf(ecgi, crnti)))
+                .flatMap(this::getUe);
+    }
+
+    /**
+     * Get from HEX string the according ECI class object.
+     *
+     * @param eciHex HEX string
+     * @return ECI object if created successfully
+     */
+    private EUTRANCellIdentifier hexToEci(String eciHex) {
+        byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
+        return new EUTRANCellIdentifier(hexBinary, 28);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/XranConfig.java b/apps/xran/src/main/java/org.onosproject.xran/impl/XranConfig.java
new file mode 100644
index 0000000..adde62e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/XranConfig.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier;
+import org.onosproject.xran.asn1lib.api.PLMNIdentity;
+import org.onosproject.xran.asn1lib.util.HexConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Xran config.
+ */
+public class XranConfig extends Config<ApplicationId> {
+
+    private static final String CELLS = "active_cells";
+
+    private static final String PLMN_ID = "plmn_id";
+
+    private static final String ECI_ID = "eci";
+
+    private static final String IP_ADDR = "ip_addr";
+
+    private static final String XRANC_IP = "xranc_bind_ip";
+
+    private static final String XRANC_PORT = "xranc_port";
+
+    private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds";
+
+    private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_ms";
+
+    private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms";
+
+    private static final String ADMISSION_SUCCESS = "admission_success";
+
+    private static final String BEARER_SUCCESS = "bearer_success";
+
+    private static final String NO_MEAS_LINK_REMOVAL = "no_meas_link_removal_ms";
+
+    private static final String IDLE_UE_REMOVAL = "idle_ue_removal_ms";
+
+    private static final String NORTHBOUND_TIMEOUT = "nb_response_timeout_ms";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * Get a list of all CELLs inside the configuration file.
+     *
+     * @return Map of CELL IP to ECGI
+     */
+    public Map<IpAddress, ECGI> activeCellSet() {
+        Map<IpAddress, ECGI> cells = new ConcurrentHashMap<>();
+
+        JsonNode cellsNode = object.get(CELLS);
+        if (cellsNode == null) {
+            log.warn("no cells have been provided!");
+            return cells;
+        }
+
+        cellsNode.forEach(cellNode -> {
+            String plmnId = cellNode.get(PLMN_ID).asText();
+            String eci = cellNode.get(ECI_ID).asText();
+
+            String ipAddress = cellNode.get(IP_ADDR).asText();
+
+            ECGI ecgi = hexToEcgi(plmnId, eci);
+            cells.put(IpAddress.valueOf(ipAddress), ecgi);
+        });
+
+        return cells;
+    }
+
+    /**
+     * Get flag for ADMISSION_SUCCESS field in configuration.
+     *
+     * @return boolean value in configuration
+     */
+    public boolean admissionFlag() {
+        JsonNode flag = object.get(ADMISSION_SUCCESS);
+        return flag != null && flag.asBoolean();
+    }
+
+    /**
+     * Get flag for BEARER_SUCCESS field in configuration.
+     *
+     * @return boolean value in configuration
+     */
+    public boolean bearerFlag() {
+        JsonNode flag = object.get(BEARER_SUCCESS);
+        return flag != null && flag.asBoolean();
+    }
+
+    /**
+     * Get IP where the XranServer binds to.
+     *
+     * @return IP address in configuration
+     */
+    public IpAddress getXrancIp() {
+        return IpAddress.valueOf(object.get(XRANC_IP).asText());
+    }
+
+    /**
+     * Get port for xRAN xranServer server to bind to from configuration.
+     *
+     * @return port number
+     */
+    public int getXrancPort() {
+        return object.get(XRANC_PORT).asInt();
+    }
+
+    /**
+     * Get config request interval from configuration.
+     *
+     * @return interval in seconds
+     */
+    public int getConfigRequestInterval() {
+        return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
+    }
+
+    /**
+     * Get rx signal interval from configuration.
+     *
+     * @return interval in milliseconds
+     */
+    public int getRxSignalInterval() {
+        return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
+    }
+
+    /**
+     * Get l2 measurement interval from configuration.
+     *
+     * @return interval in milliseconds
+     */
+    public int getL2MeasInterval() {
+        return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
+    }
+
+    /**
+     * Get removal time of link after not getting measurement from configuration.
+     *
+     * @return interval in milliseconds
+     */
+    public int getNoMeasLinkRemoval() {
+        return object.get(NO_MEAS_LINK_REMOVAL).asInt();
+    }
+
+    /**
+     * Get removal time of UE after being IDLE from configuration.
+     *
+     * @return interval in milliseconds
+     */
+    public int getIdleUeRemoval() {
+        return object.get(IDLE_UE_REMOVAL).asInt();
+    }
+
+    /**
+     * Get northbound timeout when waiting for responses from configuration.
+     *
+     * @return interval in milliseconds
+     */
+    public int getNorthBoundTimeout() {
+        return object.get(NORTHBOUND_TIMEOUT).asInt();
+    }
+
+    /**
+     * Get ECGI from HEX representation of PLMN_ID and ECI.
+     *
+     * @param plmnId HEX string of PLMN_ID
+     * @param eci    HEX string of ECI
+     * @return new ECGI object
+     */
+    private ECGI hexToEcgi(String plmnId, String eci) {
+        byte[] bytes = HexConverter.fromShortHexString(plmnId);
+        byte[] bytearray = DatatypeConverter.parseHexBinary(eci);
+
+        InputStream inputStream = new ByteArrayInputStream(bytearray);
+
+        PLMNIdentity plmnIdentity = new PLMNIdentity(bytes);
+        EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28);
+
+        ECGI ecgi = new ECGI();
+        ecgi.setEUTRANcellIdentifier(eutranCellIdentifier);
+        ecgi.setPLMNIdentity(plmnIdentity);
+        try {
+            ecgi.decode(inputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return ecgi;
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranChannelHandler.java b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranChannelHandler.java
new file mode 100644
index 0000000..e0285c3
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranChannelHandler.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.controller;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.sctp.SctpMessage;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.pdu.XrancPdu;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.URISyntaxException;
+
+/**
+ * Xran channel handler.
+ */
+@Sharable
+public class XranChannelHandler extends ChannelInboundHandlerAdapter {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(XranChannelHandler.class);
+
+    private final XranServer xranServer;
+
+    XranChannelHandler(XranServer xranServer) {
+        this.xranServer = xranServer;
+    }
+
+    /**
+     * Given PDU construct an SCTP message.
+     *
+     * @param pdu PDU packet
+     * @return SCTP message
+     * @throws IOException IO exception
+     */
+    public static SctpMessage getSctpMessage(XrancPdu pdu)  {
+        BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
+
+        try {
+            pdu.encode(os);
+        } catch (IOException e) {
+          log.warn(ExceptionUtils.getFullStackTrace(e));
+        }
+
+        log.debug("Sending message: {}", pdu);
+        final ByteBuf buf = Unpooled.buffer(os.getArray().length);
+        for (int i = 0; i < buf.capacity(); i++) {
+            buf.writeByte(os.getArray()[i]);
+        }
+        return new SctpMessage(0, 0, buf);
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) throws IOException, URISyntaxException {
+        final SocketAddress address = ctx.channel().remoteAddress();
+        if (!(address instanceof InetSocketAddress)) {
+            log.warn("Invalid client connection. Xran Cell is indentifed based on IP");
+            ctx.close();
+            return;
+        }
+
+        final InetSocketAddress inetAddress = (InetSocketAddress) address;
+        final String host = inetAddress.getHostString();
+        log.info("New client connected to the Server: {}", host);
+
+        log.info("Adding device...");
+
+        xranServer.deviceAgent.addConnectedCell(host, ctx);
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws IOException, InterruptedException {
+        SctpMessage sctpMessage = (SctpMessage) msg;
+        ByteBuf byteBuf = sctpMessage.content();
+
+        byte[] bytes = new byte[byteBuf.readableBytes()];
+        byteBuf.readBytes(bytes);
+
+        XrancPdu recvPdu = new XrancPdu();
+
+        InputStream inputStream = new ByteArrayInputStream(bytes);
+
+        recvPdu.decode(inputStream);
+
+        xranServer.packetAgent.handlePacket(recvPdu, ctx);
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        log.info("Client dropped the connection");
+
+        final SocketAddress address = ctx.channel().remoteAddress();
+        if (!(address instanceof InetSocketAddress)) {
+            log.warn("Invalid client connection. Xran Cell is indentifed based on IP");
+            ctx.close();
+            return;
+        }
+
+        final InetSocketAddress inetAddress = (InetSocketAddress) address;
+        final String host = inetAddress.getHostString();
+
+        xranServer.deviceAgent.removeConnectedCell(host);
+
+        ctx.close();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        log.warn("exceptionCaught: {}", ExceptionUtils.getStackTrace(cause));
+        cause.printStackTrace();
+        ctx.close();
+    }
+}
+
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranManager.java b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranManager.java
new file mode 100644
index 0000000..0df580f
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranManager.java
@@ -0,0 +1,1485 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.controller;
+
+import com.google.common.collect.Sets;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.sctp.SctpMessage;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostEvent;
+import org.onosproject.net.host.HostListener;
+import org.onosproject.net.host.HostService;
+import org.onosproject.xran.XranDeviceAgent;
+import org.onosproject.xran.XranDeviceListener;
+import org.onosproject.xran.XranHostAgent;
+import org.onosproject.xran.XranHostListener;
+import org.onosproject.xran.XranPacketProcessor;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranStore;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.ERABID;
+import org.onosproject.xran.asn1lib.api.ERABParams;
+import org.onosproject.xran.asn1lib.api.ERABParamsItem;
+import org.onosproject.xran.asn1lib.api.Hysteresis;
+import org.onosproject.xran.asn1lib.api.MeasID;
+import org.onosproject.xran.asn1lib.api.MeasObject;
+import org.onosproject.xran.asn1lib.api.PCIARFCN;
+import org.onosproject.xran.asn1lib.api.PropScell;
+import org.onosproject.xran.asn1lib.api.QOffsetRange;
+import org.onosproject.xran.asn1lib.api.RadioRepPerServCell;
+import org.onosproject.xran.asn1lib.api.ReportConfig;
+import org.onosproject.xran.asn1lib.api.SchedMeasRepPerServCell;
+import org.onosproject.xran.asn1lib.api.TimeToTrigger;
+import org.onosproject.xran.asn1lib.api.TrafficSplitPercentage;
+import org.onosproject.xran.asn1lib.ber.types.BerBoolean;
+import org.onosproject.xran.asn1lib.ber.types.BerEnum;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.pdu.BearerAdmissionRequest;
+import org.onosproject.xran.asn1lib.pdu.BearerAdmissionResponse;
+import org.onosproject.xran.asn1lib.pdu.BearerAdmissionStatus;
+import org.onosproject.xran.asn1lib.pdu.BearerReleaseInd;
+import org.onosproject.xran.asn1lib.pdu.CellConfigReport;
+import org.onosproject.xran.asn1lib.pdu.CellConfigRequest;
+import org.onosproject.xran.asn1lib.pdu.HOComplete;
+import org.onosproject.xran.asn1lib.pdu.HOFailure;
+import org.onosproject.xran.asn1lib.pdu.HORequest;
+import org.onosproject.xran.asn1lib.pdu.L2MeasConfig;
+import org.onosproject.xran.asn1lib.pdu.PDCPMeasReportPerUe;
+import org.onosproject.xran.asn1lib.pdu.RRCMeasConfig;
+import org.onosproject.xran.asn1lib.pdu.RRMConfig;
+import org.onosproject.xran.asn1lib.pdu.RRMConfigStatus;
+import org.onosproject.xran.asn1lib.pdu.RXSigMeasReport;
+import org.onosproject.xran.asn1lib.pdu.RadioMeasReportPerCell;
+import org.onosproject.xran.asn1lib.pdu.RadioMeasReportPerUE;
+import org.onosproject.xran.asn1lib.pdu.ScellAdd;
+import org.onosproject.xran.asn1lib.pdu.ScellAddStatus;
+import org.onosproject.xran.asn1lib.pdu.ScellDelete;
+import org.onosproject.xran.asn1lib.pdu.SchedMeasReportPerCell;
+import org.onosproject.xran.asn1lib.pdu.SchedMeasReportPerUE;
+import org.onosproject.xran.asn1lib.pdu.TrafficSplitConfig;
+import org.onosproject.xran.asn1lib.pdu.UEAdmissionRequest;
+import org.onosproject.xran.asn1lib.pdu.UEAdmissionResponse;
+import org.onosproject.xran.asn1lib.pdu.UEAdmissionStatus;
+import org.onosproject.xran.asn1lib.pdu.UECapabilityEnquiry;
+import org.onosproject.xran.asn1lib.pdu.UECapabilityInfo;
+import org.onosproject.xran.asn1lib.pdu.UEContextUpdate;
+import org.onosproject.xran.asn1lib.pdu.UEReconfigInd;
+import org.onosproject.xran.asn1lib.pdu.UEReleaseInd;
+import org.onosproject.xran.asn1lib.pdu.XrancPdu;
+import org.onosproject.xran.impl.XranConfig;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibLink;
+import org.onosproject.xran.impl.entities.RnibUe;
+import org.onosproject.xran.impl.identifiers.ContextUpdateHandler;
+import org.onosproject.xran.impl.identifiers.EcgiCrntiPair;
+import org.onosproject.xran.impl.identifiers.LinkId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.xran.impl.controller.XranChannelHandler.getSctpMessage;
+import static org.onosproject.xran.impl.entities.RnibCell.decodeDeviceId;
+import static org.onosproject.xran.impl.entities.RnibCell.uri;
+import static org.onosproject.xran.impl.entities.RnibUe.hostIdtoUEId;
+
+/**
+ * Created by dimitris on 7/20/17.
+ */
+@Component(immediate = true)
+@Service
+public class XranManager implements XranService {
+    protected static final String XRAN_APP_ID = "org.onosproject.xran";
+    protected static final Class<XranConfig> CONFIG_CLASS = XranConfig.class;
+
+    protected static final Logger log =
+            LoggerFactory.getLogger(XranManager.class);
+
+    /* CONFIG */
+    protected final InternalNetworkConfigListener configListener =
+            new InternalNetworkConfigListener();
+
+    /* VARIABLES */
+    protected final XranServer xranServer = new XranServer();
+    protected XranConfig xranConfig;
+    protected ApplicationId appId;
+    protected int northboundTimeout;
+
+    /* Services */
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected HostService hostService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry registry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigService configService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected XranStore xranStore;
+
+    protected ConfigFactory<ApplicationId, XranConfig> xranConfigFactory =
+            new ConfigFactory<ApplicationId, XranConfig>(
+                    SubjectFactories.APP_SUBJECT_FACTORY, CONFIG_CLASS, "xran") {
+                @Override
+                public XranConfig createConfig() {
+                    return new XranConfig();
+                }
+            };
+
+    /* MAPS */
+    protected ConcurrentMap<IpAddress, ECGI> legitCells = new ConcurrentHashMap<>();
+    protected ConcurrentMap<ECGI, SynchronousQueue<String>> hoMap = new ConcurrentHashMap<>();
+    protected ConcurrentMap<ECGI, SynchronousQueue<String>> rrmCellMap = new ConcurrentHashMap<>();
+    protected ConcurrentMap<CRNTI, SynchronousQueue<String>> scellAddMap = new ConcurrentHashMap<>();
+    // Map used to keep messages in pairs (HO Complete - CTX Update, Adm Status - CTX Update)
+    protected ConcurrentMap<EcgiCrntiPair, ContextUpdateHandler> contextUpdateMap = new ConcurrentHashMap<>();
+
+    /* QUEUE */
+    protected BlockingQueue<Long> ueIdQueue = new LinkedBlockingQueue<>();
+
+    /* AGENTS */
+    protected InternalXranDeviceAgent deviceAgent = new InternalXranDeviceAgent();
+    protected InternalXranHostAgent hostAgent = new InternalXranHostAgent();
+    protected InternalXranPacketAgent packetAgent = new InternalXranPacketAgent();
+
+    /* LISTENERS */
+    protected Set<XranDeviceListener> xranDeviceListeners = new CopyOnWriteArraySet<>();
+    protected Set<XranHostListener> xranHostListeners = new CopyOnWriteArraySet<>();
+    protected InternalDeviceListener deviceListener = new InternalDeviceListener();
+    protected InternalHostListener hostListener = new InternalHostListener();
+
+    @Activate
+    public void activate() {
+        appId = coreService.registerApplication(XRAN_APP_ID);
+
+        configService.addListener(configListener);
+        registry.registerConfigFactory(xranConfigFactory);
+        deviceService.addListener(deviceListener);
+        hostService.addListener(hostListener);
+
+        xranStore.setController(this);
+
+        log.info("XRAN XranServer v5 Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        deviceService.removeListener(deviceListener);
+        hostService.removeListener(hostListener);
+        configService.removeListener(configListener);
+        registry.unregisterConfigFactory(xranConfigFactory);
+
+        cleanup();
+
+        log.info("XRAN XranServer v5 Stopped");
+    }
+
+    /**
+     * Cleanup when application is deactivated.
+     */
+    private void cleanup() {
+        xranStore.getUeNodes().forEach(ue -> xranHostListeners.forEach(l -> l.hostRemoved(ue.getHostId())));
+
+        xranStore.getCellNodes().forEach(cell -> xranDeviceListeners
+                .forEach(l -> l.deviceRemoved(deviceId(uri(cell.getEcgi())))));
+
+        xranServer.stop();
+
+        legitCells.clear();
+        hoMap.clear();
+        rrmCellMap.clear();
+        scellAddMap.clear();
+        contextUpdateMap.clear();
+        ueIdQueue.clear();
+        xranDeviceListeners.clear();
+        xranHostListeners.clear();
+    }
+
+    @Override
+    public Optional<SynchronousQueue<String>> sendHoRequest(RnibLink linkT, RnibLink linkS) {
+        ECGI ecgiT = linkT.getLinkId().getEcgi(),
+                ecgiS = linkS.getLinkId().getEcgi();
+
+        Optional<ChannelHandlerContext> ctxT = xranStore.getCtx(ecgiT),
+                ctxS = xranStore.getCtx(ecgiS);
+
+        return xranStore.getCrnti(linkT.getLinkId().getUeId()).map(crnti -> {
+            SynchronousQueue<String> queue = new SynchronousQueue<>();
+
+            XrancPdu xrancPdu = HORequest.constructPacket(crnti, ecgiS, ecgiT);
+
+            // temporary map that has ECGI source of a handoff to a queue waiting for REST response.
+            hoMap.put(ecgiS, queue);
+
+            ctxT.ifPresent(ctx -> ctx.writeAndFlush(getSctpMessage(xrancPdu)));
+            ctxS.ifPresent(ctx -> ctx.writeAndFlush(getSctpMessage(xrancPdu)));
+
+            // FIXME: only works for one HO at a time.
+            try {
+                ueIdQueue.put(linkT.getLinkId().getUeId());
+            } catch (InterruptedException e) {
+                log.error(ExceptionUtils.getFullStackTrace(e));
+            }
+
+            return Optional.of(queue);
+        }).orElse(Optional.empty());
+    }
+
+    @Override
+    public void addListener(XranDeviceListener listener) {
+        xranDeviceListeners.add(listener);
+    }
+
+    @Override
+    public void addListener(XranHostListener listener) {
+        xranHostListeners.add(listener);
+    }
+
+    @Override
+    public void removeListener(XranDeviceListener listener) {
+        xranDeviceListeners.remove(listener);
+    }
+
+    @Override
+    public void removeListener(XranHostListener listener) {
+        xranHostListeners.remove(listener);
+    }
+
+    @Override
+    public int getNorthboundTimeout() {
+        return northboundTimeout;
+    }
+
+    @Override
+    public Optional<SynchronousQueue<String>> sendModifiedRrm(RRMConfig rrmConfig) {
+        ECGI ecgi = rrmConfig.getEcgi();
+        Optional<ChannelHandlerContext> optionalCtx = xranStore.getCtx(ecgi);
+
+        // if ctx exists then create the queue and send the message
+        return optionalCtx.flatMap(ctx -> {
+            XrancPdu pdu;
+            pdu = RRMConfig.constructPacket(rrmConfig);
+            ctx.writeAndFlush(getSctpMessage(pdu));
+            SynchronousQueue<String> queue = new SynchronousQueue<>();
+            rrmCellMap.put(ecgi, queue);
+            return Optional.of(queue);
+        });
+    }
+
+    @Override
+    public Optional<SynchronousQueue<String>> sendScellAdd(RnibLink link) {
+        RnibCell secondaryCell = link.getLinkId().getCell();
+        // find primary cell
+        return xranStore.getPrimaryCell(link.getLinkId().getUe()).flatMap(primaryCell -> {
+                    ECGI primaryEcgi = primaryCell.getEcgi();
+                    // get ctx for the primary cell
+                    return xranStore.getCtx(primaryEcgi).flatMap(ctx ->
+                            // check if configuration exists
+                            secondaryCell.getOptConf().flatMap(cellReport -> {
+                                        PCIARFCN pciarfcn = new PCIARFCN();
+                                        pciarfcn.setPci(cellReport.getPci());
+                                        pciarfcn.setEarfcnDl(cellReport.getEarfcnDl());
+
+                                        PropScell propScell = new PropScell();
+                                        propScell.setPciArfcn(pciarfcn);
+
+                                        // search crnti of specific UE
+                                        return xranStore.getCrnti(link.getLinkId().getUeId()).flatMap(crnti -> {
+                                            SynchronousQueue<String> queue;
+                                            XrancPdu pdu = ScellAdd
+                                                    .constructPacket(primaryEcgi, crnti, propScell);
+
+                                            ctx.writeAndFlush(getSctpMessage(pdu));
+                                            queue = new SynchronousQueue<>();
+                                            scellAddMap.put(crnti, queue);
+
+                                            return Optional.of(queue);
+                                        });
+                                    }
+                            )
+                    );
+                }
+        );
+    }
+
+    @Override
+    public boolean sendScellDelete(RnibLink link) {
+        RnibCell secondaryCell = link.getLinkId().getCell();
+        // find primary cell
+        return xranStore.getPrimaryCell(link.getLinkId().getUe()).map(primaryCell -> {
+            ECGI primaryEcgi = primaryCell.getEcgi();
+            // get ctx for the primary cell
+            return xranStore.getCtx(primaryEcgi).map(ctx ->
+                    // check if config exists
+                    secondaryCell.getOptConf().map(cellReport -> {
+                        PCIARFCN pciarfcn = new PCIARFCN();
+                        pciarfcn.setPci(cellReport.getPci());
+                        pciarfcn.setEarfcnDl(cellReport.getEarfcnDl());
+
+                        // check if crnti for UE exists
+                        return xranStore.getCrnti(link.getLinkId().getUeId()).map(crnti -> {
+                            XrancPdu pdu = ScellDelete.constructPacket(primaryEcgi, crnti, pciarfcn);
+                            ctx.writeAndFlush(getSctpMessage(pdu));
+                            link.setType(RnibLink.Type.NON_SERVING);
+                            return true;
+                        }).orElse(false);
+                    }).orElse(false)
+            ).orElse(false);
+        }).orElse(false);
+    }
+
+    /**
+     * Timer to delete UE after being IDLE.
+     *
+     * @param ue UE entity
+     */
+    private void restartTimer(RnibUe ue) {
+        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+        ue.setExecutor(executor);
+        executor.schedule(
+                () -> {
+                    if (ue.getState().equals(RnibUe.State.IDLE)) {
+                        hostAgent.removeConnectedHost(ue);
+                        log.info("UE is removed after {} ms of IDLE", xranConfig.getIdleUeRemoval());
+                    } else {
+                        log.info("UE not removed cause its ACTIVE");
+                    }
+                },
+                xranConfig.getIdleUeRemoval(),
+                TimeUnit.MILLISECONDS
+        );
+    }
+
+    /**
+     * Timer to delete LINK after not receiving measurements.
+     *
+     * @param link LINK entity
+     */
+    private void restartTimer(RnibLink link) {
+        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+        link.setExecutor(executor);
+        executor.schedule(
+                () -> {
+                    LinkId linkId = link.getLinkId();
+                    xranStore.removeLink(linkId);
+                    log.info("Link is removed after not receiving Meas Reports for {} ms",
+                            xranConfig.getNoMeasLinkRemoval());
+                },
+                xranConfig.getNoMeasLinkRemoval(),
+                TimeUnit.MILLISECONDS
+        );
+    }
+
+    /**
+     * Request measurement configuration field of specified UE.
+     *
+     * @param primary primary CELL
+     * @param ue      UE entity
+     */
+    // TODO
+    private void populateMeasConfig(RnibCell primary, RnibUe ue) {
+        RRCMeasConfig.MeasObjects measObjects = new RRCMeasConfig.MeasObjects();
+        RRCMeasConfig.MeasIds measIds = new RRCMeasConfig.MeasIds();
+        // get ctx for cell
+        xranStore.getCtx(primary.getEcgi()).ifPresent(ctx -> {
+            // iterate through all cells
+            final int[] index = {0};
+            xranStore.getCellNodes().forEach(cell ->
+                    // set pciarfcn if config exists
+                    cell.getOptConf().ifPresent(cellReport -> {
+                                // PCIARFCN
+                                PCIARFCN pciarfcn = new PCIARFCN();
+                                pciarfcn.setPci(cellReport.getPci());
+                                pciarfcn.setEarfcnDl(cellReport.getEarfcnDl());
+
+                                // MEAS OBJECT
+                                MeasObject measObject = new MeasObject();
+                                MeasObject.MeasCells measCells = new MeasObject.MeasCells();
+                                measObject.setMeasCells(measCells);
+                                measObject.setDlFreq(cellReport.getEarfcnDl());
+                                measCells.setPci(cellReport.getPci());
+                                measCells.setCellIndividualOffset(new QOffsetRange(0));
+                                measObjects.getMeasObject().add(measObject);
+
+                                // MEAS ID
+                                MeasID measID = new MeasID();
+                                MeasID.Action action = new MeasID.Action();
+                                action.setHototarget(new BerBoolean(false));
+                                measID.setAction(action);
+                                measID.setReportconfigId(new BerInteger(0));
+                                measID.setMeasobjectId(new BerInteger(index[0]++));
+                                measIds.getMeasID().add(measID);
+                            }
+                    )
+            );
+            // REPORT CONFIG
+
+            RRCMeasConfig.ReportConfigs reportConfigs = new RRCMeasConfig.ReportConfigs();
+            ReportConfig reportConfig = reportConfigs.getReportConfig().get(0);
+
+            reportConfig.setReportQuantity(new BerEnum(0));
+            reportConfig.setTriggerQuantity(new BerEnum(0));
+
+            ReportConfig.ReportParams reportParams = new ReportConfig.ReportParams();
+            reportParams.setHysteresis(new Hysteresis(0));
+            reportParams.setParams(new ReportConfig.ReportParams.Params());
+            reportParams.setTimetotrigger(new TimeToTrigger(0));
+
+            reportConfig.setReportParams(reportParams);
+
+            // construct a rx sig meas conf packet
+            XrancPdu xrancPdu = RRCMeasConfig.constructPacket(
+                    primary.getEcgi(),
+                    ue.getCrnti(),
+                    measObjects,
+                    reportConfigs,
+                    measIds,
+                    xranConfig.getRxSignalInterval()
+            );
+            ue.setMeasConfig(xrancPdu.getBody().getRRCMeasConfig());
+            ctx.writeAndFlush(getSctpMessage(xrancPdu));
+        });
+    }
+
+    public void panic(XrancPdu recvPdu) {
+        throw new IllegalArgumentException("Received illegal packet: " + recvPdu.toString());
+    }
+
+    /**
+     * Internal device listener.
+     */
+    class InternalDeviceListener implements DeviceListener {
+
+        @Override
+        public void event(DeviceEvent event) {
+            log.info("Device Event {}", event);
+            switch (event.type()) {
+                case DEVICE_ADDED: {
+                    try {
+                        ECGI ecgi = decodeDeviceId(event.subject().id());
+                        // move this to a routine service
+                        xranStore.getCell(ecgi).ifPresent(cell -> {
+                            ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+                            executor.scheduleAtFixedRate(
+                                    () -> {
+                                        // populate config if it does not exist
+                                        if (!cell.getOptConf().isPresent()) {
+                                            // if channel context is present then send the config request
+                                            xranStore.getCtx(ecgi).ifPresent(ctx -> {
+                                                XrancPdu xrancPdu = CellConfigRequest.constructPacket(ecgi);
+                                                ctx.writeAndFlush(getSctpMessage(xrancPdu));
+                                            });
+                                        } else {
+                                            // iterate through all UEs
+                                            xranStore.getUeNodes().forEach(ue -> xranStore.getPrimaryCell(ue)
+                                                    .ifPresent(primaryCell -> populateMeasConfig(primaryCell, ue)));
+
+                                            // send l2 meas interval
+                                            xranStore.getCtx(ecgi).ifPresent(ctx -> {
+                                                XrancPdu xrancPdu = L2MeasConfig
+                                                        .constructPacket(ecgi, xranConfig.getL2MeasInterval());
+                                                cell.getMeasConfig().setL2MeasConfig(xrancPdu.getBody()
+                                                        .getL2MeasConfig());
+                                                SctpMessage sctpMessage = getSctpMessage(xrancPdu);
+                                                ctx.writeAndFlush(sctpMessage);
+
+                                                executor.shutdown();
+                                            });
+                                        }
+                                    },
+                                    0,
+                                    xranConfig.getConfigRequestInterval(),
+                                    TimeUnit.SECONDS
+                            );
+                        });
+                    } catch (IOException e) {
+                        log.error(ExceptionUtils.getFullStackTrace(e));
+                    }
+                    break;
+                }
+                default: {
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     * Internal host listener.
+     */
+    class InternalHostListener implements HostListener {
+
+        @Override
+        public void event(HostEvent event) {
+            log.info("Host Event {}", event);
+            switch (event.type()) {
+                case HOST_ADDED:
+                case HOST_MOVED: {
+                    xranStore.getUe(hostIdtoUEId(event.subject().id())).ifPresent(ue -> xranStore.getPrimaryCell(ue)
+                            .ifPresent(cell -> {
+                                ue.setMeasConfig(null);
+
+                                // move this to a routine service
+                                ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+                                executor.scheduleAtFixedRate(
+                                        () -> {
+                                            if (cell.getVersion() >= 3) {
+                                                if (!Optional.ofNullable(ue.getCapability()).isPresent()) {
+                                                    xranStore.getCtx(cell.getEcgi()).ifPresent(ctx -> {
+                                                        XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket(
+                                                                cell.getEcgi(),
+                                                                ue.getCrnti());
+                                                        ctx.writeAndFlush(getSctpMessage(xrancPdu));
+                                                    });
+                                                } else {
+                                                    executor.shutdown();
+                                                }
+                                            } else {
+                                                executor.shutdown();
+                                            }
+
+                                        },
+                                        0,
+                                        xranConfig.getConfigRequestInterval(),
+                                        TimeUnit.MILLISECONDS
+                                );
+                                if (ue.getMeasConfig() == null) {
+                                    populateMeasConfig(cell, ue);
+                                }
+                            }));
+                    break;
+                }
+                default: {
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     * Internal xran device agent.
+     */
+    public class InternalXranDeviceAgent implements XranDeviceAgent {
+
+        private final Logger log = LoggerFactory.getLogger(InternalXranDeviceAgent.class);
+
+        @Override
+        public boolean addConnectedCell(String host, ChannelHandlerContext ctx) {
+            log.info("addConnectedCell: {}", host);
+            // check configuration if the cell is inside the accepted list
+            return Optional.ofNullable(legitCells.get(IpAddress.valueOf(host))).map(ecgi -> {
+                log.info("Device exists in configuration; registering...");
+                // check if cell is not already registered
+                if (!xranStore.getCell(ecgi).isPresent()) {
+                    RnibCell storeCell = new RnibCell();
+                    storeCell.setEcgi(ecgi);
+                    xranStore.storeCtx(storeCell, ctx);
+                    xranDeviceListeners.forEach(l -> l.deviceAdded(storeCell));
+                    return true;
+                }
+                return false;
+            }).orElseGet(() -> {
+                        log.error("Device is not a legit source; ignoring...");
+                        ctx.close();
+                        return false;
+                    }
+            );
+        }
+
+        @Override
+        public boolean removeConnectedCell(String host) {
+            log.info("removeConnectedCell: {}", host);
+            ECGI ecgi = legitCells.get(IpAddress.valueOf(host));
+
+            xranStore.getLinks(ecgi).forEach(rnibLink -> {
+                rnibLink.getLinkId().getUe().setState(RnibUe.State.IDLE);
+                restartTimer(rnibLink.getLinkId().getUe());
+                xranStore.removeLink(rnibLink.getLinkId());
+            });
+
+            if (xranStore.removeCell(ecgi)) {
+                xranDeviceListeners.forEach(l -> l.deviceRemoved(deviceId(uri(ecgi))));
+                return true;
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Internal xran host agent.
+     */
+    public class InternalXranHostAgent implements XranHostAgent {
+
+        @Override
+        public boolean addConnectedHost(RnibUe ue, RnibCell cell, ChannelHandlerContext ctx) {
+            log.info("addConnectedHost: {}", ue);
+            if (ue.getId() != null && xranStore.getUe(ue.getId()).isPresent()) {
+                xranStore.putPrimaryLink(cell, ue);
+
+                Set<ECGI> ecgiSet = Sets.newConcurrentHashSet();
+
+                xranStore.getLinks(ue.getId())
+                        .stream()
+                        .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
+                        .findFirst()
+                        .ifPresent(l -> ecgiSet.add(l.getLinkId().getEcgi()));
+
+                xranHostListeners.forEach(l -> l.hostAdded(ue, ecgiSet));
+                return true;
+            } else {
+                xranStore.storeUe(cell, ue);
+                xranStore.putPrimaryLink(cell, ue);
+
+                Set<ECGI> ecgiSet = Sets.newConcurrentHashSet();
+                ecgiSet.add(cell.getEcgi());
+                xranHostListeners.forEach(l -> l.hostAdded(ue, ecgiSet));
+                return true;
+            }
+
+        }
+
+        @Override
+        public boolean removeConnectedHost(RnibUe ue) {
+            log.info("removeConnectedHost: {}", ue);
+            xranStore.getLinks(ue.getId()).forEach(rnibLink -> xranStore.removeLink(rnibLink.getLinkId()));
+            if (xranStore.removeUe(ue.getId())) {
+                xranHostListeners.forEach(l -> l.hostRemoved(ue.getHostId()));
+                return true;
+            }
+            return false;
+        }
+    }
+
+    public class InternalXranPacketAgent implements XranPacketProcessor {
+        @Override
+        public void handlePacket(XrancPdu recvPdu, ChannelHandlerContext ctx)
+                throws IOException, InterruptedException {
+            int apiID = recvPdu.getHdr().getApiId().intValue();
+            log.debug("Received message: {}", recvPdu);
+            switch (apiID) {
+                // Cell Config Report
+                case 1: {
+                    CellConfigReport report = recvPdu.getBody().getCellConfigReport();
+                    handleCellconfigreport(report, recvPdu.getHdr().getVer().toString());
+                    break;
+                }
+                // UE Admission Request
+                case 2: {
+                    UEAdmissionRequest ueAdmissionRequest = recvPdu.getBody().getUEAdmissionRequest();
+                    handleUeadmissionRequest(ueAdmissionRequest, ctx);
+                    break;
+                }
+                // UE Admission Status
+                case 4: {
+                    UEAdmissionStatus ueAdmissionStatus = recvPdu.getBody().getUEAdmissionStatus();
+                    handleAdmissionStatus(ueAdmissionStatus, ctx);
+                    break;
+                }
+                // UE Context Update
+                case 5: {
+                    UEContextUpdate ueContextUpdate = recvPdu.getBody().getUEContextUpdate();
+                    handleUeContextUpdate(ueContextUpdate, ctx);
+                    break;
+                }
+                // UE Reconfig Ind
+                case 6: {
+                    UEReconfigInd ueReconfigInd = recvPdu.getBody().getUEReconfigInd();
+                    handleUeReconfigInd(ueReconfigInd);
+                    break;
+                }
+                // UE Release Ind
+                case 7: {
+                    // If xRANc wants to deactivate UE, we pass UEReleaseInd from xRANc to eNB.
+                    UEReleaseInd ueReleaseInd = recvPdu.getBody().getUEReleaseInd();
+                    handleUeReleaseInd(ueReleaseInd);
+                    break;
+                }
+                // Bearer Admission Request
+                case 8: {
+                    BearerAdmissionRequest bearerAdmissionRequest = recvPdu.getBody().getBearerAdmissionRequest();
+                    handleBearerAdmissionRequest(bearerAdmissionRequest, ctx);
+                    break;
+                }
+                // Bearer Admission Status
+                case 10: {
+                    BearerAdmissionStatus bearerAdmissionStatus = recvPdu.getBody().getBearerAdmissionStatus();
+                    // TODO: implement
+                    break;
+                }
+                // Bearer Release Ind
+                case 11: {
+                    BearerReleaseInd bearerReleaseInd = recvPdu.getBody().getBearerReleaseInd();
+                    handleBearerReleaseInd(bearerReleaseInd);
+                    break;
+                }
+                // HO Failure
+                case 13: {
+                    HOFailure hoFailure = recvPdu.getBody().getHOFailure();
+                    handleHoFailure(hoFailure);
+                    break;
+                }
+                // HO Complete
+                case 14: {
+                    HOComplete hoComplete = recvPdu.getBody().getHOComplete();
+                    handleHoComplete(hoComplete, ctx);
+                    break;
+                }
+                // RX Sig Meas Report
+                case 15: {
+                    RXSigMeasReport rxSigMeasReport = recvPdu.getBody().getRXSigMeasReport();
+                    handleRxSigMeasReport(rxSigMeasReport);
+                    break;
+                }
+                // Radio Meas Report per UE
+                case 17: {
+                    RadioMeasReportPerUE radioMeasReportPerUE = recvPdu.getBody().getRadioMeasReportPerUE();
+                    handleRadioMeasReportPerUe(radioMeasReportPerUE);
+                    break;
+                }
+                // Radio Meas Report per Cell
+                case 18: {
+                    RadioMeasReportPerCell radioMeasReportPerCell = recvPdu.getBody().getRadioMeasReportPerCell();
+                    handleRadioMeasReportPerCell(radioMeasReportPerCell);
+                    break;
+                }
+                // Sched Meas Report per UE
+                case 19: {
+                    SchedMeasReportPerUE schedMeasReportPerUE = recvPdu.getBody().getSchedMeasReportPerUE();
+                    handleSchedMeasReportPerUe(schedMeasReportPerUE);
+                    break;
+                }
+                // Sched Meas Report per Cell
+                case 20: {
+                    SchedMeasReportPerCell schedMeasReportPerCell = recvPdu.getBody().getSchedMeasReportPerCell();
+                    handleSchedMeasReportPerCell(schedMeasReportPerCell);
+                    break;
+                }
+                // PDCP Meas Report per UE
+                case 21: {
+                    PDCPMeasReportPerUe pdcpMeasReportPerUe = recvPdu.getBody().getPDCPMeasReportPerUe();
+                    handlePdcpMeasReportPerUe(pdcpMeasReportPerUe);
+                    break;
+                }
+                // UE Capability Enquiry
+                case 22: {
+                    UECapabilityEnquiry ueCapabilityEnquiry = recvPdu.getBody().getUECapabilityEnquiry();
+                    handleUecapabilityenquiry(ueCapabilityEnquiry, ctx);
+                    break;
+                }
+                // UE Capability Info
+                case 23: {
+                    UECapabilityInfo capabilityInfo = recvPdu.getBody().getUECapabilityInfo();
+                    handleCapabilityInfo(capabilityInfo);
+                    break;
+                }
+                // Scell Add Status
+                case 25: {
+                    ScellAddStatus scellAddStatus = recvPdu.getBody().getScellAddStatus();
+                    handleScellAddStatus(scellAddStatus);
+                    break;
+                }
+                // RRM Config Status
+                case 28: {
+                    // Decode RRMConfig Status
+                    RRMConfigStatus rrmConfigStatus = recvPdu.getBody().getRRMConfigStatus();
+                    handleRrmConfigStatus(rrmConfigStatus);
+                    break;
+                }
+                // SeNB Add
+                case 29: {
+                    // TODO: implement
+                    break;
+                }
+                // SeNB Add Status
+                case 30: {
+                    // TODO: implement
+                    break;
+                }
+                // SeNB Delete
+                case 31: {
+                    // TODO: implement
+                    break;
+                }
+                // Traffic Split Config
+                case 32: {
+                    TrafficSplitConfig trafficSplitConfig = recvPdu.getBody().getTrafficSplitConfig();
+                    handleTrafficSplitConfig(trafficSplitConfig);
+                    break;
+                }
+                // HO Cause
+                case 33: {
+                    // TODO: implement
+                    break;
+                }
+                case 34: {
+                    // TODO: implement
+                    break;
+                }
+                // Cell Config Request
+                case 0:
+                    // UE Admission Response
+                case 3:
+                    // Bearer Admission Response
+                case 9:
+                    // HO Request
+                case 12:
+                    // L2 Meas Config
+                case 16:
+                    // Scell Add
+                case 24:
+                    // Scell Delete
+                case 26:
+                    // RRM Config
+                case 27:
+                default: {
+                    panic(recvPdu);
+                }
+            }
+
+        }
+
+        /**
+         * Handle Cellconfigreport.
+         *
+         * @param report  CellConfigReport
+         * @param version String version ID
+         */
+        private void handleCellconfigreport(CellConfigReport report, String version) {
+            ECGI ecgi = report.getEcgi();
+
+            xranStore.getCell(ecgi).ifPresent(cell -> {
+                cell.setVersion(version);
+                cell.setConf(report);
+                xranStore.storePciArfcn(cell);
+            });
+        }
+
+        /**
+         * Handle Ueadmissionrequest.
+         *
+         * @param ueAdmissionRequest UEAdmissionRequest
+         * @param ctx                ChannelHandlerContext
+         * @throws IOException IO Exception
+         */
+        private void handleUeadmissionRequest(UEAdmissionRequest ueAdmissionRequest, ChannelHandlerContext ctx)
+                throws IOException {
+            ECGI ecgi = ueAdmissionRequest.getEcgi();
+
+            xranStore.getCell(ecgi).map(c -> {
+                CRNTI crnti = ueAdmissionRequest.getCrnti();
+                XrancPdu sendPdu = UEAdmissionResponse.constructPacket(ecgi, crnti, xranConfig.admissionFlag());
+                ctx.writeAndFlush(getSctpMessage(sendPdu));
+                return 1;
+            }).orElseGet(() -> {
+                log.warn("Could not find ECGI in registered cells: {}", ecgi);
+                return 0;
+            });
+        }
+
+        /**
+         * Handle UEAdmissionStatus.
+         *
+         * @param ueAdmissionStatus UEAdmissionStatus
+         * @param ctx               ChannelHandlerContext
+         */
+        private void handleAdmissionStatus(UEAdmissionStatus ueAdmissionStatus, ChannelHandlerContext ctx) {
+            xranStore.getUe(ueAdmissionStatus.getEcgi(), ueAdmissionStatus.getCrnti()).ifPresent(ue -> {
+                if (ueAdmissionStatus.getAdmEstStatus().value.intValue() == 0) {
+                    ue.setState(RnibUe.State.ACTIVE);
+                } else {
+                    ue.setState(RnibUe.State.IDLE);
+                }
+            });
+
+            if (ueAdmissionStatus.getAdmEstStatus().value.intValue() == 0) {
+                EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair
+                        .valueOf(ueAdmissionStatus.getEcgi(), ueAdmissionStatus.getCrnti());
+                contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> {
+                    if (v == null) {
+                        v = new ContextUpdateHandler();
+                    }
+                    if (v.setAdmissionStatus(ueAdmissionStatus)) {
+                        handlePairedPackets(v.getContextUpdate(), ctx, false);
+                        v.reset();
+                    }
+                    return v;
+                });
+            }
+        }
+
+        /**
+         * Handle UEContextUpdate.
+         *
+         * @param ueContextUpdate UEContextUpdate
+         * @param ctx             ChannelHandlerContext
+         */
+        private void handleUeContextUpdate(UEContextUpdate ueContextUpdate, ChannelHandlerContext ctx) {
+            EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair
+                    .valueOf(ueContextUpdate.getEcgi(), ueContextUpdate.getCrnti());
+
+            contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> {
+                if (v == null) {
+                    v = new ContextUpdateHandler();
+                }
+                if (v.setContextUpdate(ueContextUpdate)) {
+                    HOComplete hoComplete = v.getHoComplete();
+                    handlePairedPackets(ueContextUpdate, ctx, hoComplete != null);
+                    if (hoComplete != null) {
+                        try {
+                            hoMap.get(hoComplete.getEcgiS()).put("Hand Over Completed");
+                        } catch (InterruptedException e) {
+                            log.error(ExceptionUtils.getFullStackTrace(e));
+                        } finally {
+                            hoMap.remove(hoComplete.getEcgiS());
+                        }
+                    }
+                    v.reset();
+                }
+                return v;
+            });
+        }
+
+        /**
+         * Handle UEReconfigInd.
+         *
+         * @param ueReconfigInd UEReconfigInd
+         */
+        private void handleUeReconfigInd(UEReconfigInd ueReconfigInd) {
+            Optional<RnibUe> ue = xranStore.getUe(ueReconfigInd.getEcgi(), ueReconfigInd.getCrntiOld());
+            Optional<RnibCell> cell = xranStore.getCell(ueReconfigInd.getEcgi());
+
+            if (ue.isPresent() && cell.isPresent()) {
+                ue.get().setCrnti(ueReconfigInd.getCrntiNew());
+                xranStore.storeCrnti(cell.get(), ue.get());
+            } else {
+                log.warn("Could not find UE with this CRNTI: {}", ueReconfigInd.getCrntiOld());
+            }
+        }
+
+        /**
+         * Handle UEReleaseInd.
+         *
+         * @param ueReleaseInd UEReleaseInd
+         */
+        private void handleUeReleaseInd(UEReleaseInd ueReleaseInd) {
+            ECGI ecgi = ueReleaseInd.getEcgi();
+            CRNTI crnti = ueReleaseInd.getCrnti();
+
+            // Check if there is an ongoing handoff and only remove if ue is not part of the handoff.
+            Long peek = ueIdQueue.peek();
+            if (peek != null) {
+                EcgiCrntiPair ecgiCrntiPair = xranStore.getCrnti().inverse().get(peek);
+                if (ecgiCrntiPair != null && ecgiCrntiPair.equals(EcgiCrntiPair.valueOf(ecgi, crnti))) {
+                    return;
+                }
+            }
+
+            xranStore.getUe(ecgi, crnti).ifPresent(ue -> {
+                ue.setState(RnibUe.State.IDLE);
+                restartTimer(ue);
+            });
+        }
+
+        /**
+         * Handle BearerAdmissionRequest.
+         *
+         * @param bearerAdmissionRequest BearerAdmissionRequest
+         * @param ctx                    ChannelHandlerContext
+         */
+        private void handleBearerAdmissionRequest(BearerAdmissionRequest bearerAdmissionRequest,
+                                                  ChannelHandlerContext ctx) {
+            ECGI ecgi = bearerAdmissionRequest.getEcgi();
+            CRNTI crnti = bearerAdmissionRequest.getCrnti();
+            ERABParams erabParams = bearerAdmissionRequest.getErabParams();
+            xranStore.getLink(ecgi, crnti).ifPresent(link -> link.setBearerParameters(erabParams));
+
+            BerInteger numErabs = bearerAdmissionRequest.getNumErabs();
+            // Encode and send Bearer Admission Response
+            XrancPdu sendPdu = BearerAdmissionResponse
+                    .constructPacket(ecgi, crnti, erabParams, numErabs, xranConfig.bearerFlag());
+            ctx.writeAndFlush(getSctpMessage(sendPdu));
+        }
+
+        /**
+         * Handle BearerReleaseInd.
+         *
+         * @param bearerReleaseInd bearer release ind
+         */
+        private void handleBearerReleaseInd(BearerReleaseInd bearerReleaseInd) {
+            ECGI ecgi = bearerReleaseInd.getEcgi();
+            CRNTI crnti = bearerReleaseInd.getCrnti();
+
+            xranStore.getLink(ecgi, crnti).ifPresent(link -> {
+                List<ERABID> erabidsRelease = bearerReleaseInd.getErabIds().getERABID();
+                List<ERABParamsItem> erabParamsItem = link.getBearerParameters().getERABParamsItem();
+
+                List<ERABParamsItem> unreleased = erabParamsItem
+                        .stream()
+                        .filter(item -> {
+                            Optional<ERABID> any = erabidsRelease.stream()
+                                    .filter(id -> id.equals(item.getId())).findAny();
+                            return !any.isPresent();
+                        }).collect(Collectors.toList());
+                link.getBearerParameters().getERABParamsItem().clear();
+                link.getBearerParameters().getERABParamsItem().addAll(new ArrayList<>(unreleased));
+            });
+        }
+
+        /**
+         * Handle HOFailure.
+         *
+         * @param hoFailure HOFailure
+         * @throws InterruptedException ueIdQueue interruption
+         */
+        private void handleHoFailure(HOFailure hoFailure) throws InterruptedException {
+            try {
+                hoMap.get(hoFailure.getEcgi())
+                        .put("Hand Over Failed with cause: " + hoFailure.getCause());
+            } catch (InterruptedException e) {
+                log.error(ExceptionUtils.getFullStackTrace(e));
+            } finally {
+                hoMap.remove(hoFailure.getEcgi());
+                ueIdQueue.take();
+            }
+        }
+
+        /**
+         * Handle HOComplete.
+         *
+         * @param hoComplete HOComplete
+         * @param ctx        ChannelHandlerContext
+         */
+        private void handleHoComplete(HOComplete hoComplete, ChannelHandlerContext ctx) {
+            EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair.valueOf(hoComplete.getEcgiT(),
+                    hoComplete.getCrntiNew());
+            contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> {
+                if (v == null) {
+                    v = new ContextUpdateHandler();
+                }
+                if (v.setHoComplete(hoComplete)) {
+                    handlePairedPackets(v.getContextUpdate(), ctx, true);
+
+                    try {
+                        hoMap.get(hoComplete.getEcgiS()).put("Hand Over Completed");
+                    } catch (InterruptedException e) {
+                        log.error(ExceptionUtils.getFullStackTrace(e));
+                    } finally {
+                        hoMap.remove(hoComplete.getEcgiS());
+                    }
+                    v.reset();
+                }
+                return v;
+            });
+        }
+
+        /**
+         * Handle RXSigMeasReport.
+         *
+         * @param rxSigMeasReport RXSigMeasReport
+         */
+        private void handleRxSigMeasReport(RXSigMeasReport rxSigMeasReport) {
+            rxSigMeasReport.getCellMeasReports().getSEQUENCEOF().forEach(
+                    cellMeasReport -> cellMeasReport.getRXSigReport().forEach(
+                            rxSigReport -> {
+                                rxSigMeasReport.getCrnti().getCRNTI().forEach(
+                                        crnti -> xranStore.getUe(rxSigMeasReport.getEcgi(), crnti).ifPresent(ue -> {
+                                            Long ueId = ue.getId();
+                                            xranStore.getCell(rxSigReport.getPciArfcn()).ifPresent(cell -> {
+                                                ECGI ecgi = cell.getEcgi();
+
+                                                Optional<RnibLink> link = xranStore.getLink(ecgi, ueId);
+                                                if (!link.isPresent()) {
+                                                    log.warn("Could not find link between: {}-{} " +
+                                                                    "| Creating non-serving link..",
+                                                            ecgi, ueId);
+                                                    link = xranStore.putNonServingLink(cell, ueId);
+                                                }
+
+                                                if (link.isPresent()) {
+                                                    if (link.get().getType().equals(RnibLink.Type.NON_SERVING)) {
+                                                        restartTimer(link.get());
+                                                    }
+
+//                                                    link.get().getMeasurements().setRxSigReport(
+//                                                        new RnibLink.Measurements.RXSigReport(
+//                                                                rxSigReport.getRsrq(),
+//                                                                rxSigReport.getRsrp(),
+//                                                                rxSigReport.get...
+//                                                        )
+//                                                    );
+                                                }
+                                            });
+                                        })
+                                );
+                            }
+                    )
+            );
+        }
+
+        /**
+         * Handle RadioMeasReportPerUE.
+         *
+         * @param radioMeasReportPerUE RadioMeasReportPerUE
+         */
+        private void handleRadioMeasReportPerUe(RadioMeasReportPerUE radioMeasReportPerUE) {
+            xranStore.getUe(radioMeasReportPerUE.getEcgi(), radioMeasReportPerUE.getCrnti()).ifPresent(ue -> {
+                Long ueId = ue.getId();
+                List<RadioRepPerServCell> servCells = radioMeasReportPerUE.getRadioReportServCells()
+                        .getRadioRepPerServCell();
+
+                servCells.forEach(servCell -> xranStore.getCell(servCell.getEcgi())
+                        .ifPresent(cell -> xranStore.getLink(cell.getEcgi(), ueId)
+                                .ifPresent(link -> {
+                                            RadioRepPerServCell.CqiHist cqiHist = servCell.getCqiHist();
+                                            final double[] values = {0, 0, 0};
+                                            final int[] i = {1};
+                                            cqiHist.getBerInteger().forEach(value -> {
+                                                        values[0] = Math.max(values[0], value.intValue());
+                                                        values[1] += i[0] * value.intValue();
+                                                        values[2] += value.intValue();
+                                                        i[0]++;
+                                                    }
+                                            );
+
+                                            link.getMeasurements().setRadioReport(
+                                                    new RnibLink.Measurements.RadioReport(
+                                                            new RnibLink.Measurements.RadioReport.Cqi(
+                                                                    cqiHist,
+                                                                    values[0],
+                                                                    values[1] / values[0]
+                                                            ),
+                                                            servCell.getRiHist(),
+                                                            servCell.getPucchSinrHist(),
+                                                            servCell.getPuschSinrHist()
+
+                                                    )
+                                            );
+                                        }
+                                )
+                        )
+                );
+            });
+        }
+
+        /**
+         * Handle RadioMeasReportPerCell.
+         *
+         * @param radioMeasReportPerCell RadioMeasReportPerCell
+         */
+        private void handleRadioMeasReportPerCell(RadioMeasReportPerCell radioMeasReportPerCell) {
+            xranStore.getCell(radioMeasReportPerCell.getEcgi()).ifPresent(
+                    cell -> cell.getMeasurements().setUlInterferenceMeasurement(
+                            new RnibCell.Measurements.ULInterferenceMeasurement(
+                                    radioMeasReportPerCell.getPuschIntfPowerHist(),
+                                    radioMeasReportPerCell.getPucchIntfPowerHist()
+                            )
+                    )
+            );
+        }
+
+        /**
+         * Handle SchedMeasReportPerUE.
+         *
+         * @param schedMeasReportPerUE SchedMeasReportPerUE
+         */
+        private void handleSchedMeasReportPerUe(SchedMeasReportPerUE schedMeasReportPerUE) {
+            xranStore.getUe(schedMeasReportPerUE.getEcgi(), schedMeasReportPerUE.getCrnti()).ifPresent(ue -> {
+                Long ueId = ue.getId();
+
+                List<SchedMeasRepPerServCell> servCells = schedMeasReportPerUE.getSchedReportServCells()
+                        .getSchedMeasRepPerServCell();
+
+                servCells.forEach(servCell -> xranStore.getCell(servCell.getEcgi())
+                        .ifPresent(cell -> xranStore.getLink(cell.getEcgi(), ueId)
+                                .ifPresent(link -> link.getMeasurements().setSchedMeasReport(
+                                        new RnibLink.Measurements.SchedMeasReport(
+                                                servCell.getQciVals(),
+                                                new RnibLink.Measurements.SchedMeasReport.ResourceUsage(
+                                                        servCell.getPrbUsage().getPrbUsageDl(),
+                                                        servCell.getPrbUsage().getPrbUsageUl()
+                                                ),
+                                                new RnibLink.Measurements.SchedMeasReport.Mcs(
+                                                        servCell.getMcsDl(),
+                                                        servCell.getMcsUl()
+                                                ),
+                                                new RnibLink.Measurements.SchedMeasReport.NumSchedTtis(
+                                                        servCell.getNumSchedTtisDl(),
+                                                        servCell.getNumSchedTtisUl()
+                                                ),
+                                                new RnibLink.Measurements.SchedMeasReport.DlRankStats(
+                                                        servCell.getRankDl1(),
+                                                        servCell.getRankDl2()
+                                                )
+                                        )
+                                )
+                                )
+                        )
+                );
+            });
+        }
+
+        /**
+         * Handle SchedMeasReportPerCell.
+         *
+         * @param schedMeasReportPerCell SchedMeasReportPerCell
+         */
+        private void handleSchedMeasReportPerCell(SchedMeasReportPerCell schedMeasReportPerCell) {
+            xranStore.getCell(schedMeasReportPerCell.getEcgi()).ifPresent(cell -> cell.getMeasurements().setPrbUsage(
+                    new RnibCell.Measurements.PrbUsage(
+                            schedMeasReportPerCell.getQciVals(),
+                            schedMeasReportPerCell.getPrbUsagePcell(),
+                            schedMeasReportPerCell.getPrbUsageScell()
+                    )
+            ));
+        }
+
+        /**
+         * Handle PDCPMeasReportPerUe.
+         *
+         * @param pdcpMeasReportPerUe PDCPMeasReportPerUe
+         */
+        private void handlePdcpMeasReportPerUe(PDCPMeasReportPerUe pdcpMeasReportPerUe) {
+            xranStore.getUe(pdcpMeasReportPerUe.getEcgi(), pdcpMeasReportPerUe.getCrnti()).ifPresent(ue -> {
+                Long ueId = ue.getId();
+                xranStore.getLink(pdcpMeasReportPerUe.getEcgi(), ueId).ifPresent(link ->
+                        link.getMeasurements().setPdcpMeasReport(
+                                new RnibLink.Measurements.PdcpMeasReport(
+                                        pdcpMeasReportPerUe.getQciVals(),
+                                        new RnibLink.Measurements.PdcpMeasReport.PdcpThroughput(
+                                                pdcpMeasReportPerUe.getThroughputDl(),
+                                                pdcpMeasReportPerUe.getThroughputUl()
+                                        ),
+                                        new RnibLink.Measurements.PdcpMeasReport.DataVol(
+                                                pdcpMeasReportPerUe.getDataVolDl(),
+                                                pdcpMeasReportPerUe.getDataVolUl()
+                                        ),
+                                        pdcpMeasReportPerUe.getPktDelayDl(),
+                                        pdcpMeasReportPerUe.getPktDiscardRateDl(),
+                                        new RnibLink.Measurements.PdcpMeasReport.PktLossRate(
+                                                pdcpMeasReportPerUe.getPktLossRateDl(),
+                                                pdcpMeasReportPerUe.getPktLossRateUl()
+                                        )
+                                )
+                        )
+                );
+            });
+        }
+
+        /**
+         * Handle UECapabilityInfo.
+         *
+         * @param capabilityInfo UECapabilityInfo
+         */
+        private void handleCapabilityInfo(UECapabilityInfo capabilityInfo) {
+            xranStore.getUe(capabilityInfo.getEcgi(), capabilityInfo.getCrnti())
+                    .ifPresent(
+                            ue -> ue.setCapability(capabilityInfo)
+                    );
+        }
+
+        /**
+         * Handle UECapabilityEnquiry.
+         *
+         * @param ueCapabilityEnquiry UECapabilityEnquiry
+         * @param ctx                 ChannelHandlerContext
+         */
+        private void handleUecapabilityenquiry(UECapabilityEnquiry ueCapabilityEnquiry, ChannelHandlerContext ctx) {
+            XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket(ueCapabilityEnquiry.getEcgi(),
+                    ueCapabilityEnquiry.getCrnti());
+            ctx.writeAndFlush(getSctpMessage(xrancPdu));
+        }
+
+        /**
+         * Handle ScellAddStatus.
+         *
+         * @param scellAddStatus ScellAddStatus
+         */
+        private void handleScellAddStatus(ScellAddStatus scellAddStatus) {
+            xranStore.getUe(scellAddStatus.getEcgi(), scellAddStatus.getCrnti()).ifPresent(ue -> {
+                Long ueId = ue.getId();
+                try {
+                    scellAddMap.get(scellAddStatus.getCrnti()).put("Scell's status: " +
+                            scellAddStatus.getStatus());
+                    final int[] i = {0};
+                    scellAddStatus.getScellsInd().getPCIARFCN().forEach(
+                            pciarfcn -> {
+                                if (scellAddStatus.getStatus().getBerEnum().get(i[0]).value.intValue() == 0) {
+                                    xranStore.getCell(pciarfcn)
+                                            .ifPresent(cell -> xranStore.getLink(cell.getEcgi(), ueId)
+                                                    .ifPresent(link -> link.setType(RnibLink.Type.SERVING_SECONDARY_CA))
+                                            );
+                                }
+                                i[0]++;
+                            }
+                    );
+
+                } catch (InterruptedException e) {
+                    log.error(ExceptionUtils.getFullStackTrace(e));
+                } finally {
+                    scellAddMap.remove(scellAddStatus.getCrnti());
+                }
+            });
+        }
+
+        /**
+         * Handle RRMConfigStatus.
+         *
+         * @param rrmConfigStatus RRMConfigStatus
+         */
+        private void handleRrmConfigStatus(RRMConfigStatus rrmConfigStatus) {
+            try {
+                rrmCellMap.get(rrmConfigStatus.getEcgi())
+                        .put("RRM Config's status: " + rrmConfigStatus.getStatus());
+            } catch (InterruptedException e) {
+                log.error(ExceptionUtils.getFullStackTrace(e));
+            } finally {
+                rrmCellMap.remove(rrmConfigStatus.getEcgi());
+            }
+        }
+
+        /**
+         * Handle TrafficSplitConfig.
+         *
+         * @param trafficSplitConfig TrafficSplitConfig
+         */
+        private void handleTrafficSplitConfig(TrafficSplitConfig trafficSplitConfig) {
+            xranStore.getUe(trafficSplitConfig.getEcgi(), trafficSplitConfig.getCrnti()).ifPresent(ue -> {
+                Long ueId = ue.getId();
+                List<TrafficSplitPercentage> splitPercentages = trafficSplitConfig
+                        .getTrafficSplitPercent().getTrafficSplitPercentage();
+
+                splitPercentages.forEach(trafficSplitPercentage -> xranStore.getCell(trafficSplitPercentage.getEcgi())
+                        .ifPresent(cell -> xranStore.getLink(cell.getEcgi(), ueId)
+                                .ifPresent(link -> link.setTrafficPercent(trafficSplitPercentage))));
+            });
+        }
+
+        /**
+         * Handle context update depending if its handoff or not.
+         *
+         * @param contextUpdate context update packet
+         * @param ctx           channel context for the CELL
+         * @param handoff       true if we handle a Hand Off
+         */
+        private void handlePairedPackets(UEContextUpdate contextUpdate, ChannelHandlerContext ctx, boolean handoff) {
+            xranStore.getCell(contextUpdate.getEcgi()).ifPresent(cell -> {
+                        Optional<RnibUe> optionalUe;
+                        if (handoff) {
+                            try {
+                                optionalUe = xranStore.getUe(ueIdQueue.take());
+                            } catch (InterruptedException e) {
+                                log.error(ExceptionUtils.getFullStackTrace(e));
+                                optionalUe = Optional.of(new RnibUe());
+                            }
+                        } else {
+                            optionalUe = Optional.of(new RnibUe());
+                        }
+
+                        optionalUe.ifPresent(ue -> {
+                            ue.getContextIds().setMmeS1apId(contextUpdate.getMMEUES1APID());
+                            ue.getContextIds().setEnbS1apId(contextUpdate.getENBUES1APID());
+                            ue.setCrnti(contextUpdate.getCrnti());
+                            hostAgent.addConnectedHost(ue, cell, ctx);
+                        });
+                    }
+            );
+        }
+    }
+
+    /**
+     * Internal class for NetworkConfigListener.
+     */
+    class InternalNetworkConfigListener implements NetworkConfigListener {
+
+        @Override
+        public void event(NetworkConfigEvent event) {
+            switch (event.type()) {
+                case CONFIG_REGISTERED:
+                    break;
+                case CONFIG_UNREGISTERED:
+                    break;
+                case CONFIG_ADDED:
+                case CONFIG_UPDATED:
+                    if (event.configClass() == CONFIG_CLASS) {
+                        handleConfigEvent(event.config());
+                    }
+                    break;
+                case CONFIG_REMOVED:
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        /**
+         * Handle config event.
+         *
+         * @param configOptional config
+         */
+        private void handleConfigEvent(Optional<Config> configOptional) {
+            configOptional.ifPresent(config -> {
+                xranConfig = (XranConfig) config;
+                northboundTimeout = xranConfig.getNorthBoundTimeout();
+                legitCells.putAll(xranConfig.activeCellSet());
+                xranServer.start(deviceAgent, hostAgent, packetAgent,
+                        xranConfig.getXrancIp(), xranConfig.getXrancPort());
+            });
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranServer.java b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranServer.java
new file mode 100644
index 0000000..8a92ffd
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/XranServer.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.controller;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.sctp.SctpChannel;
+import io.netty.channel.sctp.nio.NioSctpServerChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import org.onlab.packet.IpAddress;
+import org.onosproject.xran.XranDeviceAgent;
+import org.onosproject.xran.XranHostAgent;
+import org.onosproject.xran.XranPacketProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by dimitris on 7/27/17.
+ */
+public class XranServer {
+    protected static final Logger log = LoggerFactory.getLogger(XranServer.class);
+    protected XranDeviceAgent deviceAgent;
+    protected XranHostAgent hostAgent;
+    protected XranPacketProcessor packetAgent;
+    private EventLoopGroup bossGroup;
+    private EventLoopGroup workerGroup;
+    private ChannelFuture channel;
+    private int port = 8007;
+    private IpAddress bindAddress = IpAddress.valueOf("0.0.0.0");
+    private boolean isRunning = false;
+
+    /**
+     * Run SCTP server.
+     */
+    public void run() {
+        final XranServer ctrl = this;
+        try {
+            ServerBootstrap b = createServerBootStrap();
+            b.childHandler(new ChannelInitializer<SctpChannel>() {
+                @Override
+                public void initChannel(SctpChannel ch) throws Exception {
+                    ch.pipeline().addLast(
+                            //new LoggingHandler(LogLevel.INFO),
+                            new XranChannelHandler(ctrl)
+                    );
+                }
+            });
+            channel = b.bind(this.bindAddress.toInetAddress(), this.port).sync();
+        } catch (Exception e) {
+            log.warn(e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Create bootstrap for server.
+     *
+     * @return server bootstrap
+     */
+    private ServerBootstrap createServerBootStrap() {
+        bossGroup = new NioEventLoopGroup(1);
+        workerGroup = new NioEventLoopGroup();
+
+        ServerBootstrap b = new ServerBootstrap();
+        b.group(bossGroup, workerGroup)
+                .channel(NioSctpServerChannel.class)
+                .handler(new LoggingHandler(LogLevel.INFO));
+        return b;
+    }
+
+    /**
+     * Initialize xranServer and start SCTP server.
+     *  @param deviceAgent device agent
+     * @param hostAgent   host agent
+     * @param packetAgent packet agent
+     * @param xrancIp     xran bind IP
+     * @param port        port of server
+     */
+    public void start(XranDeviceAgent deviceAgent, XranHostAgent hostAgent, XranPacketProcessor packetAgent,
+                      IpAddress xrancIp, int port) {
+        if (isRunning && (this.port != port || !this.bindAddress.equals(xrancIp))) {
+            stop();
+            this.deviceAgent = deviceAgent;
+            this.hostAgent = hostAgent;
+            this.packetAgent = packetAgent;
+            this.port = port;
+            this.bindAddress = xrancIp;
+            run();
+        } else if (!isRunning) {
+            this.deviceAgent = deviceAgent;
+            this.hostAgent = hostAgent;
+            this.packetAgent = packetAgent;
+            this.port = port;
+            this.bindAddress = xrancIp;
+            run();
+            isRunning = true;
+        }
+    }
+
+    /**
+     * Stop SCTP server.
+     */
+    public void stop() {
+        if (isRunning) {
+            channel.channel().close();
+            bossGroup.shutdownGracefully();
+            workerGroup.shutdownGracefully();
+            isRunning = false;
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/controller/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/package-info.java
new file mode 100644
index 0000000..6b047e5
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/controller/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/21/17.
+ */
+package org.onosproject.xran.impl.controller;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibCell.java b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibCell.java
new file mode 100644
index 0000000..6370a05
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibCell.java
@@ -0,0 +1,676 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.entities;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.PRBUsage;
+import org.onosproject.xran.asn1lib.api.XICICPA;
+import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.pdu.CellConfigReport;
+import org.onosproject.xran.asn1lib.pdu.L2MeasConfig;
+import org.onosproject.xran.asn1lib.pdu.RRCMeasConfig;
+import org.onosproject.xran.asn1lib.pdu.RRMConfig;
+import org.onosproject.xran.asn1lib.pdu.RadioMeasReportPerCell;
+import org.onosproject.xran.asn1lib.pdu.SchedMeasReportPerCell;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+
+/**
+ * R-NIB Cell and its properties.
+ */
+@JsonPropertyOrder({
+        "ECGI",
+        "Configuration",
+        "RRMConfiguration",
+        "MeasConfig",
+        "Measurements"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RnibCell {
+    @JsonIgnore
+    private static final String SCHEME = "xran";
+
+    @JsonProperty("ECGI")
+    private ECGI ecgi;
+
+    @JsonProperty("Configuration")
+    private Optional<CellConfigReport> conf = Optional.empty();
+
+    @JsonProperty("RRMConfiguration")
+    private RRMConfig rrmConfig = new RRMConfig();
+
+    @JsonProperty("MeasConfig")
+    private MeasConfig measConfig = new MeasConfig();
+
+    @JsonProperty("Measurements")
+    private Measurements measurements = new Measurements();
+
+    @JsonIgnore
+    private String version = "5";
+
+    /**
+     * Encode ECGI and obtain its URI.
+     *
+     * @param ecgi ECGI
+     * @return URI
+     */
+    public static URI uri(ECGI ecgi) {
+        if (ecgi != null) {
+            try {
+                BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
+                ecgi.encode(os);
+                String message = DatatypeConverter.printHexBinary(os.getArray());
+                return new URI(SCHEME, message, null);
+            } catch (URISyntaxException | IOException e) {
+                return null;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Obtain ECGI from the device ID.
+     *
+     * @param deviceId ID of the device
+     * @return ECGI
+     * @throws IOException I0 Exception for ByteArrayInputStream
+     */
+    public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
+        String uri = deviceId.toString();
+        String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
+
+        ECGI ecgi = new ECGI();
+        byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
+        InputStream inputStream = new ByteArrayInputStream(bytearray);
+
+        ecgi.decode(inputStream);
+        return ecgi;
+    }
+
+    /**
+     * Get version ID.
+     *
+     * @return version ID
+     */
+    public int getVersion() {
+        return Integer.parseInt(version);
+    }
+
+    /**
+     * Set version ID.
+     *
+     * @param version version ID
+     */
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    /**
+     * Get RRMConfig.
+     *
+     * @return RRMConfig
+     */
+    public RRMConfig getRrmConfig() {
+        return rrmConfig;
+    }
+
+    /**
+     * Set RRMConfig properties.
+     *
+     * @param rrmConfig RRMConfig
+     */
+    public void setRrmConfig(RRMConfig rrmConfig) {
+        this.rrmConfig = rrmConfig;
+    }
+
+    /**
+     * Get ECGI.
+     *
+     * @return ECGI
+     */
+    public ECGI getEcgi() {
+        return ecgi;
+    }
+
+    /**
+     * Set ECGI.
+     *
+     * @param ecgi ECGI
+     */
+    public void setEcgi(ECGI ecgi) {
+        this.ecgi = ecgi;
+    }
+
+    /**
+     * Get cell config report.
+     *
+     * @return Optional CellConfig Report
+     */
+    public Optional<CellConfigReport> getOptConf() {
+        return conf;
+    }
+
+    /**
+     * Get cell config report.
+     *
+     * @return CellConfig Report
+     */
+    public CellConfigReport getConf() {
+        return conf.get();
+    }
+
+    /**
+     * Set cell config report.
+     *
+     * @param conf Cell config report
+     */
+    public void setConf(CellConfigReport conf) {
+        this.conf = Optional.ofNullable(conf);
+    }
+
+    public MeasConfig getMeasConfig() {
+        return measConfig;
+    }
+
+    public void setMeasConfig(MeasConfig measConfig) {
+        this.measConfig = measConfig;
+    }
+
+    public Measurements getMeasurements() {
+        return measurements;
+    }
+
+    public void setMeasurements(Measurements measurements) {
+        this.measurements = measurements;
+    }
+
+    /**
+     * Modify the RRM Config parameters of cell.
+     *
+     * @param rrmConfigNode RRMConfig parameters to modify obtained from REST call
+     * @param ueList        List of all UEs
+     * @throws Exception p_a size not equal to UE size
+     */
+    public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) throws Exception {
+        RRMConfig.Crnti crnti = new RRMConfig.Crnti();
+        ueList.forEach(ue -> crnti.getCRNTI().add(ue.getCrnti()));
+
+        JsonNode pA = rrmConfigNode.path("p_a");
+        if (!pA.isMissingNode()) {
+            RRMConfig.Pa pa = new RRMConfig.Pa();
+            if (pA.isArray()) {
+                if (ueList.size() == pA.size()) {
+                    List<XICICPA> collect = Stream.of(pA)
+                            .map(val -> new XICICPA(val.asInt()))
+                            .collect(Collectors.toList());
+                    pa.getXICICPA().clear();
+                    pa.getXICICPA().addAll(collect);
+                } else {
+                    throw new Exception("p_a size is not the same as UE size");
+                }
+            }
+            rrmConfig.setPa(pa);
+        }
+
+        JsonNode startPrbDl1 = rrmConfigNode.path("start_prb_dl");
+        if (!startPrbDl1.isMissingNode()) {
+            RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
+            if (startPrbDl1.isArray()) {
+                if (ueList.size() == startPrbDl1.size()) {
+                    List<BerInteger> collect = Stream.of(startPrbDl1)
+                            .map(val -> new BerInteger(val.asInt()))
+                            .collect(Collectors.toList());
+                    startPrbDl.getBerInteger().clear();
+                    startPrbDl.getBerInteger().addAll(collect);
+                } else {
+                    throw new Exception("start_prb_dl size is not the same as UE size");
+                }
+            }
+            rrmConfig.setStartPrbDl(startPrbDl);
+        }
+
+        JsonNode endPrbDl1 = rrmConfigNode.path("end_prb_dl");
+        if (!endPrbDl1.isMissingNode()) {
+            RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
+            if (endPrbDl1.isArray()) {
+                if (ueList.size() == endPrbDl1.size()) {
+                    List<BerInteger> collect = Stream.of(endPrbDl1)
+                            .map(val -> new BerInteger(val.asInt()))
+                            .collect(Collectors.toList());
+                    endPrbDl.getBerInteger().clear();
+                    endPrbDl.getBerInteger().addAll(collect);
+                } else {
+                    throw new Exception("end_prb_dl size is not the same as UE size");
+                }
+            }
+            rrmConfig.setEndPrbDl(endPrbDl);
+        }
+
+        JsonNode frameBitmaskDl = rrmConfigNode.path("sub_frame_bitmask_dl");
+        if (!frameBitmaskDl.isMissingNode()) {
+            RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
+            if (frameBitmaskDl.isArray()) {
+                List<BerBitString> collect = Stream.of(frameBitmaskDl)
+                        .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
+                        .collect(Collectors.toList());
+                subframeBitmaskDl.getBerBitString().clear();
+                subframeBitmaskDl.getBerBitString().addAll(collect);
+            } else {
+                throw new Exception("sub_frame_bitmask_dl size is not the same as UE size");
+            }
+            rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl);
+        }
+
+        JsonNode startPrbUl1 = rrmConfigNode.path("start_prb_ul");
+        if (!startPrbUl1.isMissingNode()) {
+            RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
+            if (startPrbUl1.isArray()) {
+                if (ueList.size() == startPrbUl1.size()) {
+                    List<BerInteger> collect = Stream.of(startPrbUl1)
+                            .map(val -> new BerInteger(val.asInt()))
+                            .collect(Collectors.toList());
+                    startPrbUl.getBerInteger().clear();
+                    startPrbUl.getBerInteger().addAll(collect);
+                } else {
+                    throw new Exception("start_prb_ul size is not the same as UE size");
+                }
+            }
+            rrmConfig.setStartPrbUl(startPrbUl);
+        }
+
+        JsonNode endPrbUl1 = rrmConfigNode.path("end_prb_ul");
+        if (!endPrbUl1.isMissingNode()) {
+            RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
+            if (endPrbUl1.isArray()) {
+                if (ueList.size() == endPrbUl1.size()) {
+                    List<BerInteger> collect = Stream.of(endPrbUl1)
+                            .map(val -> new BerInteger(val.asInt()))
+                            .collect(Collectors.toList());
+                    endPrbUl.getBerInteger().clear();
+                    endPrbUl.getBerInteger().addAll(collect);
+                } else {
+                    throw new Exception("end_prb_ul size is not the same as UE size");
+                }
+            }
+            rrmConfig.setEndPrbUl(endPrbUl);
+        }
+
+        JsonNode uePusch = rrmConfigNode.path("p0_ue_pusch");
+        if (!uePusch.isMissingNode()) {
+            RRMConfig.P0UePusch p0UePusch = new RRMConfig.P0UePusch();
+            if (uePusch.isArray()) {
+                if (ueList.size() == uePusch.size()) {
+                    List<BerInteger> collect = Stream.of(uePusch)
+                            .map(val -> new BerInteger(val.asInt()))
+                            .collect(Collectors.toList());
+                    p0UePusch.getBerInteger().clear();
+                    p0UePusch.getBerInteger().addAll(collect);
+                } else {
+                    throw new Exception("p0_ue_pusch size is not the same as UE size");
+                }
+            }
+            rrmConfig.setP0UePusch(p0UePusch);
+        }
+
+        JsonNode frameBitmaskUl = rrmConfigNode.path("sub_frame_bitmask_ul");
+        if (!frameBitmaskUl.isMissingNode()) {
+            RRMConfig.SubframeBitmaskUl subframeBitmaskUl = new RRMConfig.SubframeBitmaskUl();
+            if (frameBitmaskUl.isArray()) {
+                List<BerBitString> collect = Stream.of(frameBitmaskUl)
+                        .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
+                        .collect(Collectors.toList());
+                subframeBitmaskUl.getBerBitString().clear();
+                subframeBitmaskUl.getBerBitString().addAll(collect);
+            } else {
+                throw new Exception("sub_frame_bitmask_ul size is not the same as UE size");
+            }
+            rrmConfig.setSubframeBitmaskUl(subframeBitmaskUl);
+        }
+
+        rrmConfig.setCrnti(crnti);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        RnibCell rnibCell = (RnibCell) o;
+
+        return ecgi.equals(rnibCell.ecgi);
+    }
+
+    @Override
+    public int hashCode() {
+        return ecgi.hashCode();
+    }
+
+    /**
+     * Object class for MeasConfig.
+     */
+    @JsonPropertyOrder({
+            "RRCMeasConfig",
+            "L2MeasConfig",
+            "timestamp"
+    })
+    @JsonIgnoreProperties(ignoreUnknown = true)
+    public static class MeasConfig {
+        @JsonProperty("timestamp")
+        WallClockTimestamp timestamp = new WallClockTimestamp();
+        @JsonProperty("RRCMeasConfig")
+        private RRCMeasConfig rrcMeasConfig;
+        @JsonProperty("L2MeasConfig")
+        private L2MeasConfig l2MeasConfig;
+
+        public MeasConfig() {
+        }
+
+        @JsonCreator
+        public MeasConfig(@JsonProperty("RRCMeasConfig") RRCMeasConfig rrcMeasConfig,
+                          @JsonProperty("L2MeasConfig") L2MeasConfig l2MeasConfig) {
+            this.rrcMeasConfig = rrcMeasConfig;
+            this.l2MeasConfig = l2MeasConfig;
+        }
+
+        public RRCMeasConfig getRrcMeasConfig() {
+            return rrcMeasConfig;
+        }
+
+        public void setRrcMeasConfig(RRCMeasConfig rrcMeasConfig) {
+            this.rrcMeasConfig = rrcMeasConfig;
+        }
+
+        public L2MeasConfig getL2MeasConfig() {
+            return l2MeasConfig;
+        }
+
+        public void setL2MeasConfig(L2MeasConfig l2MeasConfig) {
+            this.l2MeasConfig = l2MeasConfig;
+        }
+
+        public long getTimestamp() {
+            return new WallClockTimestamp().unixTimestamp() - timestamp.unixTimestamp();
+        }
+
+        public void setTimestamp(WallClockTimestamp timestamp) {
+            this.timestamp = timestamp;
+        }
+
+        @Override
+        public String toString() {
+            return "MeasConfig{" +
+                    "rrcMeasConfig=" + rrcMeasConfig +
+                    ", l2MeasConfig=" + l2MeasConfig +
+                    ", timestamp=" + getTimestamp() +
+                    '}';
+        }
+    }
+
+    /**
+     * Object class for PrbUsage.
+     */
+    @JsonPropertyOrder({
+            "UL-InterferenceMeasurement",
+            "PRB-Usage",
+    })
+    @JsonIgnoreProperties(ignoreUnknown = true)
+    public static class Measurements {
+        @JsonProperty("UL-InterferenceMeasurement")
+        ULInterferenceMeasurement ulInterferenceMeasurement = new ULInterferenceMeasurement();
+        @JsonProperty("PRB-Usage")
+        PrbUsage prbUsage = new PrbUsage();
+
+        public Measurements() {
+        }
+
+        @JsonCreator
+        public Measurements(
+                @JsonProperty("UL-InterferenceMeasurement") ULInterferenceMeasurement ulInterferenceMeasurement,
+                @JsonProperty("PRB-Usage") PrbUsage prbUsage
+        ) {
+            this.ulInterferenceMeasurement = ulInterferenceMeasurement;
+            this.prbUsage = prbUsage;
+        }
+
+        public ULInterferenceMeasurement getUlInterferenceMeasurement() {
+            return ulInterferenceMeasurement;
+        }
+
+        public void setUlInterferenceMeasurement(ULInterferenceMeasurement ulInterferenceMeasurement) {
+            this.ulInterferenceMeasurement = ulInterferenceMeasurement;
+        }
+
+        public PrbUsage getPrbUsage() {
+            return prbUsage;
+        }
+
+        public void setPrbUsage(PrbUsage prbUsage) {
+            this.prbUsage = prbUsage;
+        }
+
+        @Override
+        public String toString() {
+            return "Measurements{" +
+                    "ulInterferenceMeasurement=" + ulInterferenceMeasurement +
+                    ", prbUsage=" + prbUsage +
+                    '}';
+        }
+
+        /**
+         * Object class for PrbUsage.
+         */
+        @JsonPropertyOrder({
+                "PUSCH",
+                "PUCCH",
+                "timestamp"
+        })
+        @JsonIgnoreProperties(ignoreUnknown = true)
+        public static class ULInterferenceMeasurement {
+            @JsonProperty("PUSCH")
+            RadioMeasReportPerCell.PuschIntfPowerHist pusch;
+            @JsonProperty("PUCCH")
+            RadioMeasReportPerCell.PucchIntfPowerHist pucch;
+            @JsonProperty("timestamp")
+            WallClockTimestamp timestamp = new WallClockTimestamp();
+
+            public ULInterferenceMeasurement() {
+            }
+
+            @JsonCreator
+            public ULInterferenceMeasurement(@JsonProperty("PUSCH") RadioMeasReportPerCell.PuschIntfPowerHist pusch,
+                                             @JsonProperty("PUCCH") RadioMeasReportPerCell.PucchIntfPowerHist pucch) {
+                this.pusch = pusch;
+                this.pucch = pucch;
+            }
+
+            public RadioMeasReportPerCell.PuschIntfPowerHist getPusch() {
+                return pusch;
+            }
+
+            public void setPusch(RadioMeasReportPerCell.PuschIntfPowerHist pusch) {
+                this.pusch = pusch;
+            }
+
+            public RadioMeasReportPerCell.PucchIntfPowerHist getPucch() {
+                return pucch;
+            }
+
+            public void setPucch(RadioMeasReportPerCell.PucchIntfPowerHist pucch) {
+                this.pucch = pucch;
+            }
+
+            public long getTimestamp() {
+                return new WallClockTimestamp().unixTimestamp() - timestamp.unixTimestamp();
+            }
+
+            public void setTimestamp(WallClockTimestamp timestamp) {
+                this.timestamp = timestamp;
+            }
+
+            @Override
+            public String toString() {
+                return "ULInterferenceMeasurement{" +
+                        "pusch=" + pusch +
+                        ", pucch=" + pucch +
+                        ", timestamp=" + getTimestamp() +
+                        '}';
+            }
+        }
+
+        /**
+         * Object class for PrbUsage.
+         */
+        @JsonPropertyOrder({
+                "QCI",
+                "primary",
+                "secondary",
+                "timestamp"
+        })
+        @JsonIgnoreProperties(ignoreUnknown = true)
+        public static class PrbUsage {
+            @JsonProperty("QCI")
+            SchedMeasReportPerCell.QciVals qci;
+            @JsonProperty("primary")
+            PRBUsage primary;
+            @JsonProperty("secondary")
+            PRBUsage secondary;
+            @JsonProperty("timestamp")
+            WallClockTimestamp timestamp = new WallClockTimestamp();
+
+            public PrbUsage() {
+            }
+
+            @JsonCreator
+            public PrbUsage(
+                    @JsonProperty("QCI") SchedMeasReportPerCell.QciVals qci,
+                    @JsonProperty("primary") PRBUsage primary,
+                    @JsonProperty("secondary") PRBUsage secondary
+            ) {
+                this.qci = qci;
+                this.primary = primary;
+                this.secondary = secondary;
+            }
+
+            /**
+             * Get QCI
+             *
+             * @return QCI
+             */
+            public SchedMeasReportPerCell.QciVals getQci() {
+                return qci;
+            }
+
+            /**
+             * Set QCI.
+             *
+             * @param qci
+             */
+            public void setQci(SchedMeasReportPerCell.QciVals qci) {
+                this.qci = qci;
+            }
+
+            /**
+             * Get primary PrbUsage.
+             *
+             * @return PrbUsage
+             */
+            public PRBUsage getPrimary() {
+                return primary;
+            }
+
+            /**
+             * Set secondary PrbUsage.
+             *
+             * @param primary PrbUsage
+             */
+            public void setPrimary(PRBUsage primary) {
+                this.primary = primary;
+            }
+
+            /**
+             * Get secondary PrbUsage.
+             *
+             * @return PrbUsage
+             */
+            public PRBUsage getSecondary() {
+                return secondary;
+            }
+
+            /**
+             * Set secondary PrbUsage.
+             *
+             * @param secondary PrbUsage
+             */
+            public void setSecondary(PRBUsage secondary) {
+                this.secondary = secondary;
+            }
+
+            /**
+             * Get time since last update.
+             *
+             * @return long Time
+             */
+            public long getTimestamp() {
+                return new WallClockTimestamp().unixTimestamp() - timestamp.unixTimestamp();
+            }
+
+
+            /**
+             * Set time since last update.
+             *
+             * @param timestamp time since last update
+             */
+            public void setTimestamp(WallClockTimestamp timestamp) {
+                this.timestamp = timestamp;
+            }
+
+            @Override
+            public String toString() {
+                return "PrbUsage{" +
+                        "qci=" + qci +
+                        ", primary=" + primary +
+                        ", secondary=" + secondary +
+                        ", timestamp=" + getTimestamp() +
+                        '}';
+            }
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibLink.java b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibLink.java
new file mode 100644
index 0000000..8505aec
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibLink.java
@@ -0,0 +1,1418 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.entities;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Lists;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.onosproject.xran.asn1lib.api.ERABParams;
+import org.onosproject.xran.asn1lib.api.PRBUsage;
+import org.onosproject.xran.asn1lib.api.RadioRepPerServCell;
+import org.onosproject.xran.asn1lib.api.SchedMeasRepPerServCell;
+import org.onosproject.xran.asn1lib.api.TrafficSplitPercentage;
+import org.onosproject.xran.asn1lib.api.XICICPA;
+import org.onosproject.xran.asn1lib.ber.types.BerBitString;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.asn1lib.pdu.PDCPMeasReportPerUe;
+import org.onosproject.xran.asn1lib.pdu.RRMConfig;
+import org.onosproject.xran.asn1lib.pdu.RXSigMeasReport;
+import org.onosproject.xran.impl.identifiers.LinkId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * R-NIB Link and its properties.
+ */
+@JsonPropertyOrder({
+        "Link-ID",
+        "Type",
+        "RRMConfiguration",
+        "TrafficPercent",
+        "BearerParameters",
+        "Measurements"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RnibLink {
+    @JsonIgnore
+    private static final Logger log =
+            LoggerFactory.getLogger(RnibLink.class);
+    @JsonProperty("Measurements")
+    private Measurements measurements = new Measurements();
+    @JsonProperty("Link-ID")
+    private LinkId linkId;
+    @JsonProperty("RRMConfiguration")
+    private RRMConfig rrmParameters;
+    @JsonProperty("TrafficPercent")
+    private TrafficSplitPercentage trafficPercent;
+    @JsonProperty("BearerParameters")
+    private ERABParams bearerParameters;
+    @JsonProperty("Type")
+    private Type type;
+    @JsonIgnore
+    private ScheduledExecutorService executor;
+
+    public RnibLink(RnibCell cell, RnibUe ue) {
+        trafficPercent = new TrafficSplitPercentage();
+        trafficPercent.setEcgi(cell.getEcgi());
+        trafficPercent.setTrafficPercentDl(new BerInteger(100));
+        trafficPercent.setTrafficPercentUl(new BerInteger(100));
+
+        executor = Executors.newSingleThreadScheduledExecutor();
+
+        type = Type.NON_SERVING;
+
+        linkId = LinkId.valueOf(cell, ue);
+
+        rrmParameters = new RRMConfig();
+        RRMConfig.Crnti crnti = new RRMConfig.Crnti();
+        crnti.getCRNTI().add(linkId.getUe().getCrnti());
+        rrmParameters.setCrnti(crnti);
+        rrmParameters.setEcgi(linkId.getEcgi());
+    }
+
+    /**
+     * Get executor.
+     *
+     * @return Timer
+     */
+    public ScheduledExecutorService getExecutor() {
+        return executor;
+    }
+
+    public void setExecutor(ScheduledExecutorService executor) {
+        this.executor.shutdown();
+        this.executor = executor;
+    }
+
+    /**
+     * Get Link ID.
+     *
+     * @return LinkID
+     */
+    @JsonProperty("Link-ID")
+    public LinkId getLinkId() {
+        return linkId;
+    }
+
+    /**
+     * Set the Link ID.
+     *
+     * @param linkId Link ID
+     */
+    @JsonProperty("Link-ID")
+    public void setLinkId(LinkId linkId) {
+        this.linkId = linkId;
+    }
+
+    /**
+     * Set the LINK ID with cell and ue.
+     *
+     * @param cell Rnib CELL
+     * @param ue   Rnib UE
+     */
+    public void setLinkId(RnibCell cell, RnibUe ue) {
+        this.linkId = LinkId.valueOf(cell, ue);
+        trafficPercent.setEcgi(cell.getEcgi());
+    }
+
+    /**
+     * Get the link type.
+     *
+     * @return Link-type
+     */
+    @JsonProperty("Type")
+    public Type getType() {
+        return type;
+    }
+
+    /**
+     * Set the link type.
+     *
+     * @param type Link-type
+     */
+    @JsonProperty("Type")
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    /**
+     * Get traffic percent.
+     *
+     * @return TrafficSplitPercentage
+     */
+    @JsonProperty("TrafficPercent")
+    public TrafficSplitPercentage getTrafficPercent() {
+        return trafficPercent;
+    }
+
+    /**
+     * Set traffic percent.
+     *
+     * @param trafficPercent TrafficSplitPercentage
+     */
+    @JsonProperty("TrafficPercent")
+    public void setTrafficPercent(TrafficSplitPercentage trafficPercent) {
+        this.trafficPercent = trafficPercent;
+    }
+
+    /**
+     * Get the Bearer Parameters.
+     *
+     * @return ERABParams
+     */
+    @JsonProperty("BearerParameters")
+    public ERABParams getBearerParameters() {
+        return bearerParameters;
+    }
+
+    /**
+     * Set the Bearer Parameters.
+     *
+     * @param bearerParameters ERABParams
+     */
+    @JsonProperty("BearerParameters")
+    public void setBearerParameters(ERABParams bearerParameters) {
+        this.bearerParameters = bearerParameters;
+    }
+
+    /**
+     * Get RRM Configuration.
+     *
+     * @return RRMConfig
+     */
+    @JsonProperty("RRMConfiguration")
+    public RRMConfig getRrmParameters() {
+        return rrmParameters;
+    }
+
+    /**
+     * Set RRM Configuration.
+     *
+     * @param rrmParameters RRMConfig
+     */
+    @JsonProperty("RRMConfiguration")
+    public void setRrmParameters(RRMConfig rrmParameters) {
+        this.rrmParameters = rrmParameters;
+    }
+
+    public Measurements getMeasurements() {
+        return measurements;
+    }
+
+    public void setMeasurements(Measurements measurements) {
+        this.measurements = measurements;
+    }
+
+    /**
+     * Modify the RRM Config parameters of link.
+     *
+     * @param rrmConfigNode RRMConfig parameters to modify obtained from REST call
+     */
+    public void modifyRrmParameters(JsonNode rrmConfigNode) {
+
+        JsonNode pA = rrmConfigNode.path("p_a");
+        if (!pA.isMissingNode()) {
+            RRMConfig.Pa pa = new RRMConfig.Pa();
+
+            List<XICICPA> collect = Lists.newArrayList();
+            collect.add(new XICICPA(pA.asInt()));
+            pa.getXICICPA().clear();
+            pa.getXICICPA().addAll(collect);
+
+            rrmParameters.setPa(pa);
+        }
+
+        JsonNode startPrbDl1 = rrmConfigNode.path("start_prb_dl");
+        if (!startPrbDl1.isMissingNode()) {
+            RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
+
+            List<BerInteger> collect = Lists.newArrayList();
+            collect.add(new BerInteger(startPrbDl1.asInt()));
+            startPrbDl.getBerInteger().clear();
+            startPrbDl.getBerInteger().addAll(collect);
+
+            rrmParameters.setStartPrbDl(startPrbDl);
+        }
+
+        JsonNode endPrbDl1 = rrmConfigNode.path("end_prb_dl");
+        if (!endPrbDl1.isMissingNode()) {
+            RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
+
+            List<BerInteger> collect = Lists.newArrayList();
+            collect.add(new BerInteger(endPrbDl1.asInt()));
+            endPrbDl.getBerInteger().clear();
+            endPrbDl.getBerInteger().addAll(collect);
+
+            rrmParameters.setEndPrbDl(endPrbDl);
+        }
+
+        JsonNode subFrameBitmaskDl = rrmConfigNode.path("sub_frame_bitmask_dl");
+        if (!subFrameBitmaskDl.isMissingNode()) {
+            RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
+            List<BerBitString> collect = Lists.newArrayList();
+
+            byte[] hexString = DatatypeConverter.parseHexBinary(subFrameBitmaskDl.asText());
+            collect.add(new BerBitString(hexString, 10));
+            subframeBitmaskDl.getBerBitString().clear();
+            subframeBitmaskDl.getBerBitString().addAll(collect);
+
+            rrmParameters.setSubframeBitmaskDl(subframeBitmaskDl);
+        }
+
+        JsonNode startPrbUl1 = rrmConfigNode.path("start_prb_ul");
+        if (!startPrbUl1.isMissingNode()) {
+            RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
+
+            List<BerInteger> collect = Lists.newArrayList();
+            collect.add(new BerInteger(startPrbUl1.asInt()));
+            startPrbUl.getBerInteger().clear();
+            startPrbUl.getBerInteger().addAll(collect);
+
+            rrmParameters.setStartPrbUl(startPrbUl);
+        }
+
+        JsonNode endPrbUl1 = rrmConfigNode.path("end_prb_ul");
+        if (!endPrbUl1.isMissingNode()) {
+            RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
+
+            List<BerInteger> collect = Lists.newArrayList();
+            collect.add(new BerInteger(endPrbUl1.asInt()));
+            endPrbUl.getBerInteger().clear();
+            endPrbUl.getBerInteger().addAll(collect);
+
+            rrmParameters.setEndPrbUl(endPrbUl);
+        }
+
+
+        JsonNode p0UePusch1 = rrmConfigNode.path("p0_ue_pusch");
+        if (!p0UePusch1.isMissingNode()) {
+            RRMConfig.P0UePusch p0UePusch = new RRMConfig.P0UePusch();
+
+            List<BerInteger> collect = Lists.newArrayList();
+            collect.add(new BerInteger(p0UePusch1.asInt()));
+            p0UePusch.getBerInteger().clear();
+            p0UePusch.getBerInteger().addAll(collect);
+
+            rrmParameters.setP0UePusch(p0UePusch);
+        }
+
+        JsonNode subFrameBitmaskUl = rrmConfigNode.path("sub_frame_bitmask_ul");
+        if (!subFrameBitmaskUl.isMissingNode()) {
+            RRMConfig.SubframeBitmaskUl subframeBitmaskUl = new RRMConfig.SubframeBitmaskUl();
+            List<BerBitString> collect = Lists.newArrayList();
+
+            byte[] hexString = DatatypeConverter.parseHexBinary(subFrameBitmaskUl.asText());
+            collect.add(new BerBitString(hexString, 10));
+            subframeBitmaskUl.getBerBitString().clear();
+            subframeBitmaskUl.getBerBitString().addAll(collect);
+
+            rrmParameters.setSubframeBitmaskUl(subframeBitmaskUl);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "RnibLink{" +
+                "measurements=" + measurements +
+                ", linkId=" + linkId +
+                ", rrmParameters=" + rrmParameters +
+                ", trafficPercent=" + trafficPercent +
+                ", bearerParameters=" + bearerParameters +
+                ", type=" + type +
+                '}';
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        RnibLink link = (RnibLink) o;
+
+        return linkId.equals(link.linkId);
+    }
+
+    @Override
+    public int hashCode() {
+        return linkId.hashCode();
+    }
+
+    /**
+     * Enum of Link-Type.
+     */
+    public enum Type {
+        SERVING_PRIMARY("serving/primary") {
+            @Override
+            public String toString() {
+                return "serving/primary";
+            }
+        },
+        SERVING_SECONDARY_CA("serving/secondary/ca") {
+            @Override
+            public String toString() {
+                return "serving/secondary/ca";
+            }
+        },
+        SERVING_SECONDARY_DC("serving/secondary/dc") {
+            @Override
+            public String toString() {
+                return "serving/secondary/dc";
+            }
+        },
+        NON_SERVING("non-serving") {
+            @Override
+            public String toString() {
+                return "non-serving";
+            }
+        };
+
+        private String name;
+
+        Type(String name) {
+            this.name = name;
+        }
+
+        /**
+         * Get enum value of link-type.
+         *
+         * @param name String representation of Enum Type
+         * @return Type
+         */
+        public static Type getEnum(String name) {
+            Optional<Type> any = Arrays.stream(Type.values()).filter(typeStr -> typeStr.name.equals(name)).findAny();
+            if (any.isPresent()) {
+                return any.get();
+            }
+            throw new IllegalArgumentException("No enum defined for string: " + name);
+        }
+    }
+
+    @JsonPropertyOrder({
+            "RXSigReport",
+            "RadioReport",
+            "SchedMeasReport",
+            "PDCPMeasReport",
+
+    })
+    @JsonIgnoreProperties(ignoreUnknown = true)
+    public static class Measurements {
+        @JsonProperty("RXSigReport")
+        RXSigReport rxSigReport = new RXSigReport();
+        @JsonProperty("RadioReport")
+        RadioReport radioReport = new RadioReport();
+        @JsonProperty("SchedMeasReport")
+        SchedMeasReport schedMeasReport = new SchedMeasReport();
+        @JsonProperty("PDCPMeasReport")
+        PdcpMeasReport pdcpMeasReport = new PdcpMeasReport();
+
+        public Measurements() {
+        }
+
+        @JsonCreator
+        public Measurements(@JsonProperty("RXSigReport") RXSigReport rxSigReport,
+                            @JsonProperty("RadioReport") RadioReport radioReport,
+                            @JsonProperty("SchedMeasReport") SchedMeasReport schedMeasReport,
+                            @JsonProperty("PDCPMeasReport") PdcpMeasReport pdcpMeasReport) {
+            this.rxSigReport = rxSigReport;
+            this.radioReport = radioReport;
+            this.schedMeasReport = schedMeasReport;
+            this.pdcpMeasReport = pdcpMeasReport;
+        }
+
+        public RXSigReport getRxSigReport() {
+            return rxSigReport;
+        }
+
+        public void setRxSigReport(RXSigReport rxSigReport) {
+            this.rxSigReport = rxSigReport;
+        }
+
+        public RadioReport getRadioReport() {
+            return radioReport;
+        }
+
+        public void setRadioReport(RadioReport radioReport) {
+            this.radioReport = radioReport;
+        }
+
+        public SchedMeasReport getSchedMeasReport() {
+            return schedMeasReport;
+        }
+
+        public void setSchedMeasReport(SchedMeasReport schedMeasReport) {
+            this.schedMeasReport = schedMeasReport;
+        }
+
+        public PdcpMeasReport getPdcpMeasReport() {
+            return pdcpMeasReport;
+        }
+
+        public void setPdcpMeasReport(PdcpMeasReport pdcpMeasReport) {
+            this.pdcpMeasReport = pdcpMeasReport;
+        }
+
+        @Override
+        public String toString() {
+            return "Measurements{" +
+                    "rxSigReport=" + rxSigReport +
+                    ", radioReport=" + radioReport +
+                    ", schedMeasReport=" + schedMeasReport +
+                    ", pdcpMeasReport=" + pdcpMeasReport +
+                    '}';
+        }
+
+        @JsonPropertyOrder({
+                "RSRP",
+                "RSRQ",
+                "meas-id",
+                "timestamp"
+        })
+        public static class RXSigReport {
+            @JsonProperty("RSRP")
+            double rsrp;
+            @JsonProperty("RSRQ")
+            double rsrq;
+            @JsonProperty("meas-id")
+            RXSigMeasReport.CellMeasReports measReports;
+            @JsonProperty("timestamp")
+            WallClockTimestamp timesincelastupdate = new WallClockTimestamp();
+
+            public RXSigReport() {
+            }
+
+            @JsonCreator
+            public RXSigReport(@JsonProperty("RSRP") double rsrp,
+                               @JsonProperty("RSRQ") double rsrq,
+                               @JsonProperty("meas-id") RXSigMeasReport.CellMeasReports measReports
+            ) {
+                this.rsrp = rsrp;
+                this.rsrq = rsrq;
+                this.measReports = measReports;
+            }
+
+            /**
+             * Get rsrp.
+             *
+             * @return double rsrp
+             */
+            public double getRsrp() {
+                return rsrp;
+            }
+
+            /**
+             * Set rsrp.
+             *
+             * @param rsrp rsrp
+             */
+            public void setRsrp(double rsrp) {
+                this.rsrp = rsrp;
+            }
+
+            /**
+             * Get rsrq.
+             *
+             * @return double rsrq
+             */
+            public double getRsrq() {
+                return rsrq;
+            }
+
+            /**
+             * Set rsrq.
+             *
+             * @param rsrq rsrq
+             */
+            public void setRsrq(double rsrq) {
+                this.rsrq = rsrq;
+            }
+
+            /**
+             * Get time since last update.
+             *
+             * @return long Time
+             */
+            public long getTimesincelastupdate() {
+                return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
+            }
+
+            /**
+             * Set time since last update.
+             *
+             * @param timesincelastupdate time since last update
+             */
+            public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
+                this.timesincelastupdate = timesincelastupdate;
+            }
+
+            public RXSigMeasReport.CellMeasReports getMeasReports() {
+                return measReports;
+            }
+
+            public void setMeasReports(RXSigMeasReport.CellMeasReports measReports) {
+                this.measReports = measReports;
+            }
+
+            @Override
+            public String toString() {
+                return "RXSigReport{" +
+                        "rsrp=" + rsrp +
+                        ", rsrq=" + rsrq +
+                        ", measReports=" + measReports +
+                        ", timestamp=" + getTimesincelastupdate() +
+                        '}';
+            }
+        }
+
+        @JsonPropertyOrder({
+                "CQI",
+                "Rank_hist",
+                "Pusch_sinr_hist",
+                "Pucch_sinr_hist",
+                "timestamp"
+        })
+        @JsonIgnoreProperties(ignoreUnknown = true)
+        public static class RadioReport {
+            @JsonProperty("CQI")
+            Cqi cqi = new Cqi();
+            @JsonProperty("Rank_hist")
+            RadioRepPerServCell.RiHist riHist;
+            @JsonProperty("Pucch_sinr_hist")
+            RadioRepPerServCell.PucchSinrHist pucchSinrHist;
+            @JsonProperty("Pusch_sinr_hist")
+            RadioRepPerServCell.PuschSinrHist puschSinrHist;
+            @JsonProperty("timestamp")
+            WallClockTimestamp timesincelastupdate = new WallClockTimestamp();
+
+            public RadioReport() {
+            }
+
+            @JsonCreator
+            public RadioReport(@JsonProperty("CQI") Cqi cqi,
+                               @JsonProperty("Rank_hist") RadioRepPerServCell.RiHist riHist,
+                               @JsonProperty("Pucch_sinr_hist") RadioRepPerServCell.PucchSinrHist pucchSinrHist,
+                               @JsonProperty("Pusch_sinr_hist") RadioRepPerServCell.PuschSinrHist puschSinrHist) {
+                this.cqi = cqi;
+                this.riHist = riHist;
+                this.pucchSinrHist = pucchSinrHist;
+                this.puschSinrHist = puschSinrHist;
+            }
+
+            public Cqi getCqi() {
+                return cqi;
+            }
+
+            public void setCqi(Cqi cqi) {
+                this.cqi = cqi;
+            }
+
+            public RadioRepPerServCell.RiHist getRiHist() {
+                return riHist;
+            }
+
+            public void setRiHist(RadioRepPerServCell.RiHist riHist) {
+                this.riHist = riHist;
+            }
+
+            public RadioRepPerServCell.PucchSinrHist getPucchSinrHist() {
+                return pucchSinrHist;
+            }
+
+            public void setPucchSinrHist(RadioRepPerServCell.PucchSinrHist pucchSinrHist) {
+                this.pucchSinrHist = pucchSinrHist;
+            }
+
+            public RadioRepPerServCell.PuschSinrHist getPuschSinrHist() {
+                return puschSinrHist;
+            }
+
+            public void setPuschSinrHist(RadioRepPerServCell.PuschSinrHist puschSinrHist) {
+                this.puschSinrHist = puschSinrHist;
+            }
+
+            /**
+             * Get time since last update.
+             *
+             * @return long Time
+             */
+            public long getTimesincelastupdate() {
+                return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
+            }
+
+            public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
+                this.timesincelastupdate = timesincelastupdate;
+            }
+
+            @Override
+            public String toString() {
+                return "RadioReport{" +
+                        "cqi=" + cqi +
+                        ", riHist=" + riHist +
+                        ", pucchSinrHist=" + pucchSinrHist +
+                        ", puschSinrHist=" + puschSinrHist +
+                        ", timestamp=" + getTimesincelastupdate() +
+                        '}';
+            }
+
+            @JsonPropertyOrder({
+                    "Hist",
+                    "Mode",
+                    "Mean",
+                    "timestamp"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class Cqi {
+                @JsonProperty("Hist")
+                RadioRepPerServCell.CqiHist hist;
+                @JsonProperty("Mode")
+                double mode;
+                @JsonProperty("Mean")
+                double mean;
+
+                public Cqi() {
+                }
+
+                @JsonCreator
+                public Cqi(@JsonProperty("Hist") RadioRepPerServCell.CqiHist hist,
+                           @JsonProperty("Mode") double mode,
+                           @JsonProperty("Mean") double mean) {
+                    this.hist = hist;
+                    this.mode = mode;
+                    this.mean = mean;
+                }
+
+                /**
+                 * Get CQIHist.
+                 *
+                 * @return CqiHist
+                 */
+                public RadioRepPerServCell.CqiHist getHist() {
+                    return hist;
+                }
+
+                /**
+                 * Get CQIHist.
+                 *
+                 * @param hist CqiHist
+                 */
+                public void setHist(RadioRepPerServCell.CqiHist hist) {
+                    this.hist = hist;
+                }
+
+                /**
+                 * Get mode.
+                 *
+                 * @return double mode
+                 */
+                public double getMode() {
+                    return mode;
+                }
+
+                /**
+                 * Set mode.
+                 *
+                 * @param mode mode
+                 */
+                public void setMode(double mode) {
+                    this.mode = mode;
+                }
+
+                /**
+                 * Get mean.
+                 *
+                 * @return double mean
+                 */
+                public double getMean() {
+                    return mean;
+                }
+
+                /**
+                 * Set mean.
+                 *
+                 * @param mean mean
+                 */
+                public void setMean(double mean) {
+                    this.mean = mean;
+                }
+
+                @Override
+                public String toString() {
+                    return "Cqi{" +
+                            "hist=" + hist +
+                            ", mode=" + mode +
+                            ", mean=" + mean +
+                            '}';
+                }
+            }
+        }
+
+        @JsonPropertyOrder({
+                "QCI",
+                "ResourceUsage",
+                "MCS",
+                "Num_Sched_TTIs",
+                "DL_rank_stats",
+                "timestamp"
+        })
+        @JsonIgnoreProperties(ignoreUnknown = true)
+        public static class SchedMeasReport {
+            @JsonProperty("QCI")
+            SchedMeasRepPerServCell.QciVals qci;
+            @JsonProperty("ResourceUsage")
+            ResourceUsage resourceUsage = new ResourceUsage();
+            @JsonProperty("MCS")
+            Mcs mcs = new Mcs();
+            @JsonProperty("Num_Sched_TTIs")
+            NumSchedTtis numSchedTtis = new NumSchedTtis();
+            @JsonProperty("DL_rank_stats")
+            DlRankStats dlRankStats = new DlRankStats();
+            @JsonProperty("timestamp")
+            WallClockTimestamp timesincelastupdate = new WallClockTimestamp();
+
+            public SchedMeasReport() {
+            }
+
+            @JsonCreator
+            public SchedMeasReport(
+                    @JsonProperty("QCI") SchedMeasRepPerServCell.QciVals qci,
+                    @JsonProperty("ResourceUsage") ResourceUsage resourceUsage,
+                    @JsonProperty("MCS") Mcs mcs,
+                    @JsonProperty("Num_Sched_TTIs") NumSchedTtis numSchedTtis,
+                    @JsonProperty("DL_rank_stats") DlRankStats dlRankStats
+            ) {
+                this.qci = qci;
+                this.resourceUsage = resourceUsage;
+                this.mcs = mcs;
+                this.numSchedTtis = numSchedTtis;
+                this.dlRankStats = dlRankStats;
+            }
+
+            public SchedMeasRepPerServCell.QciVals getQci() {
+                return qci;
+            }
+
+            public void setQci(SchedMeasRepPerServCell.QciVals qci) {
+                this.qci = qci;
+            }
+
+            public ResourceUsage getResourceUsage() {
+                return resourceUsage;
+            }
+
+            public void setResourceUsage(ResourceUsage resourceUsage) {
+                this.resourceUsage = resourceUsage;
+            }
+
+            public Mcs getMcs() {
+                return mcs;
+            }
+
+            public void setMcs(Mcs mcs) {
+                this.mcs = mcs;
+            }
+
+            public NumSchedTtis getNumSchedTtis() {
+                return numSchedTtis;
+            }
+
+            public void setNumSchedTtis(NumSchedTtis numSchedTtis) {
+                this.numSchedTtis = numSchedTtis;
+            }
+
+            public DlRankStats getDlRankStats() {
+                return dlRankStats;
+            }
+
+            public void setDlRankStats(DlRankStats dlRankStats) {
+                this.dlRankStats = dlRankStats;
+            }
+
+            public long getTimesincelastupdate() {
+                return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
+            }
+
+            public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
+                this.timesincelastupdate = timesincelastupdate;
+            }
+
+            @Override
+            public String toString() {
+                return "SchedMeasReport{" +
+                        "qci=" + qci +
+                        ", resourceUsage=" + resourceUsage +
+                        ", mcs=" + mcs +
+                        ", numSchedTtis=" + numSchedTtis +
+                        ", dlRankStats=" + dlRankStats +
+                        ", timesincelastupdate=" + getTimesincelastupdate() +
+                        '}';
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class ResourceUsage {
+                @JsonProperty("dl")
+                PRBUsage.PrbUsageDl dl;
+                @JsonProperty("ul")
+                PRBUsage.PrbUsageUl ul;
+
+                public ResourceUsage() {
+                }
+
+                @JsonCreator
+                public ResourceUsage(@JsonProperty("dl") PRBUsage.PrbUsageDl dl,
+                                     @JsonProperty("ul") PRBUsage.PrbUsageUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                /**
+                 * Get DL.
+                 *
+                 * @return Dl
+                 */
+                public PRBUsage.PrbUsageDl getDl() {
+                    return dl;
+                }
+
+                /**
+                 * Set DL.
+                 *
+                 * @param dl DL
+                 */
+                public void setDl(PRBUsage.PrbUsageDl dl) {
+                    this.dl = dl;
+                }
+
+                /**
+                 * Get UL.
+                 *
+                 * @return Ul
+                 */
+                public PRBUsage.PrbUsageUl getUl() {
+                    return ul;
+                }
+
+                /**
+                 * Set UL.
+                 *
+                 * @param ul Ul
+                 */
+                public void setUl(PRBUsage.PrbUsageUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String toString() {
+                    return "ResourceUsage{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class Mcs {
+                SchedMeasRepPerServCell.McsDl dl;
+                SchedMeasRepPerServCell.McsUl ul;
+
+                public Mcs() {
+                }
+
+                @JsonCreator
+                public Mcs(@JsonProperty("dl") SchedMeasRepPerServCell.McsDl dl,
+                           @JsonProperty("ul") SchedMeasRepPerServCell.McsUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                /**
+                 * Get DL.
+                 *
+                 * @return Dl
+                 */
+                public SchedMeasRepPerServCell.McsDl getDl() {
+                    return dl;
+                }
+
+                /**
+                 * Set DL.
+                 *
+                 * @param dl DL
+                 */
+                public void setDl(SchedMeasRepPerServCell.McsDl dl) {
+                    this.dl = dl;
+                }
+
+                /**
+                 * Get UL.
+                 *
+                 * @return Ul
+                 */
+                public SchedMeasRepPerServCell.McsUl getUl() {
+                    return ul;
+                }
+
+                /**
+                 * Set UL.
+                 *
+                 * @param ul Ul
+                 */
+                public void setUl(SchedMeasRepPerServCell.McsUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String toString() {
+                    return "mcs{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class NumSchedTtis {
+                @JsonProperty("dl")
+                SchedMeasRepPerServCell.NumSchedTtisDl dl;
+                @JsonProperty("ul")
+                SchedMeasRepPerServCell.NumSchedTtisUl ul;
+
+                public NumSchedTtis() {
+                }
+
+                @JsonCreator
+                public NumSchedTtis(@JsonProperty("dl") SchedMeasRepPerServCell.NumSchedTtisDl dl,
+                                    @JsonProperty("ul") SchedMeasRepPerServCell.NumSchedTtisUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                public SchedMeasRepPerServCell.NumSchedTtisDl getDl() {
+                    return dl;
+                }
+
+                public void setDl(SchedMeasRepPerServCell.NumSchedTtisDl dl) {
+                    this.dl = dl;
+                }
+
+                public SchedMeasRepPerServCell.NumSchedTtisUl getUl() {
+                    return ul;
+                }
+
+                public void setUl(SchedMeasRepPerServCell.NumSchedTtisUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String toString() {
+                    return "NumSchedTtis{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+
+            @JsonPropertyOrder({
+                    "Rank-1",
+                    "Rank-2"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class DlRankStats {
+                @JsonProperty("Rank-1")
+                SchedMeasRepPerServCell.RankDl1 rankDl1;
+                @JsonProperty("Rank-2")
+                SchedMeasRepPerServCell.RankDl2 rankDl2;
+
+                public DlRankStats() {
+                }
+
+                @JsonCreator
+                public DlRankStats(@JsonProperty("Rank-1") SchedMeasRepPerServCell.RankDl1 rankDl1,
+                                   @JsonProperty("Rank-2") SchedMeasRepPerServCell.RankDl2 rankDl2) {
+                    this.rankDl1 = rankDl1;
+                    this.rankDl2 = rankDl2;
+                }
+
+                public SchedMeasRepPerServCell.RankDl1 getRankDl1() {
+                    return rankDl1;
+                }
+
+                public void setRankDl1(SchedMeasRepPerServCell.RankDl1 rankDl1) {
+                    this.rankDl1 = rankDl1;
+                }
+
+                public SchedMeasRepPerServCell.RankDl2 getRankDl2() {
+                    return rankDl2;
+                }
+
+                public void setRankDl2(SchedMeasRepPerServCell.RankDl2 rankDl2) {
+                    this.rankDl2 = rankDl2;
+                }
+
+                @Override
+                public String toString() {
+                    return "DlRankStats{" +
+                            "rankDl1=" + rankDl1 +
+                            ", rankDl2=" + rankDl2 +
+                            '}';
+                }
+            }
+        }
+
+        @JsonPropertyOrder({
+                "QCI",
+                "PDCPThroughput",
+                "Data_vol",
+                "Pkt_delay_dl",
+                "Pkt_discard_rate_dl",
+                "Pkt_loss_rate",
+                "timestamp"
+        })
+        @JsonIgnoreProperties(ignoreUnknown = true)
+        public static class PdcpMeasReport {
+            @JsonProperty("QCI")
+            PDCPMeasReportPerUe.QciVals qci = new PDCPMeasReportPerUe.QciVals();
+            @JsonProperty("PDCPThroughput")
+            PdcpThroughput pdcpThroughput = new PdcpThroughput();
+            @JsonProperty("Data_vol")
+            DataVol dataVol = new DataVol();
+            @JsonProperty("Pkt_delay_dl")
+            PDCPMeasReportPerUe.PktDelayDl pktDelayDl;
+            @JsonProperty("Pkt_discard_rate_dl")
+            PDCPMeasReportPerUe.PktDiscardRateDl pktDiscardRateDl;
+            @JsonProperty("Pkt_loss_rate")
+            PktLossRate pktLossRate = new PktLossRate();
+            @JsonProperty("timestamp")
+            WallClockTimestamp timesincelastupdate = new WallClockTimestamp();
+
+            public PdcpMeasReport() {
+            }
+
+            @JsonCreator
+            public PdcpMeasReport(
+                    @JsonProperty("QCI") PDCPMeasReportPerUe.QciVals qci,
+                    @JsonProperty("PDCPThroughput") PdcpThroughput pdcpThroughput,
+                    @JsonProperty("Data_vol") DataVol dataVol,
+                    @JsonProperty("Pkt_delay_dl") PDCPMeasReportPerUe.PktDelayDl pktDelayDl,
+                    @JsonProperty("Pkt_discard_rate_dl") PDCPMeasReportPerUe.PktDiscardRateDl pktDiscardRateDl,
+                    @JsonProperty("Pkt_loss_rate") PktLossRate pktLossRate
+            ) {
+                this.qci = qci;
+                this.pdcpThroughput = pdcpThroughput;
+                this.dataVol = dataVol;
+                this.pktDelayDl = pktDelayDl;
+                this.pktDiscardRateDl = pktDiscardRateDl;
+                this.pktLossRate = pktLossRate;
+            }
+
+            public PDCPMeasReportPerUe.QciVals getQci() {
+                return qci;
+            }
+
+            public void setQci(PDCPMeasReportPerUe.QciVals qci) {
+                this.qci = qci;
+            }
+
+            public PdcpThroughput getPdcpThroughput() {
+                return pdcpThroughput;
+            }
+
+            public void setPdcpThroughput(PdcpThroughput pdcpThroughput) {
+                this.pdcpThroughput = pdcpThroughput;
+            }
+
+            public DataVol getDataVol() {
+                return dataVol;
+            }
+
+            public void setDataVol(DataVol dataVol) {
+                this.dataVol = dataVol;
+            }
+
+            public PDCPMeasReportPerUe.PktDelayDl getPktDelayDl() {
+                return pktDelayDl;
+            }
+
+            public void setPktDelayDl(PDCPMeasReportPerUe.PktDelayDl pktDelayDl) {
+                this.pktDelayDl = pktDelayDl;
+            }
+
+            public PDCPMeasReportPerUe.PktDiscardRateDl getPktDiscardRateDl() {
+                return pktDiscardRateDl;
+            }
+
+            public void setPktDiscardRateDl(PDCPMeasReportPerUe.PktDiscardRateDl pktDiscardRateDl) {
+                this.pktDiscardRateDl = pktDiscardRateDl;
+            }
+
+            public PktLossRate getPktLossRate() {
+                return pktLossRate;
+            }
+
+            public void setPktLossRate(PktLossRate pktLossRate) {
+                this.pktLossRate = pktLossRate;
+            }
+
+            public long getTimesincelastupdate() {
+                return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
+            }
+
+            public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
+                this.timesincelastupdate = timesincelastupdate;
+            }
+
+            @Override
+            public String toString() {
+                return "PdcpMeasReport{" +
+                        "qci=" + qci +
+                        ", pdcpThroughput=" + pdcpThroughput +
+                        ", dataVol=" + dataVol +
+                        ", pktDelayDl=" + pktDelayDl +
+                        ", pktDiscardRateDl=" + pktDiscardRateDl +
+                        ", pktLossRate=" + pktLossRate +
+                        ", timesincelastupdate=" + getTimesincelastupdate() +
+                        '}';
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class PdcpThroughput {
+                @JsonProperty("dl")
+                private PDCPMeasReportPerUe.ThroughputDl dl;
+                @JsonProperty("ul")
+                private PDCPMeasReportPerUe.ThroughputUl ul;
+
+                public PdcpThroughput() {
+                }
+
+                @JsonCreator
+                public PdcpThroughput(@JsonProperty("dl") PDCPMeasReportPerUe.ThroughputDl dl,
+                                      @JsonProperty("ul") PDCPMeasReportPerUe.ThroughputUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                /**
+                 * Get DL.
+                 *
+                 * @return Dl
+                 */
+                public PDCPMeasReportPerUe.ThroughputDl getDl() {
+                    return dl;
+                }
+
+                /**
+                 * Set DL.
+                 *
+                 * @param dl DL
+                 */
+                public void setDl(PDCPMeasReportPerUe.ThroughputDl dl) {
+                    this.dl = dl;
+                }
+
+                /**
+                 * Get UL.
+                 *
+                 * @return Ul
+                 */
+                public PDCPMeasReportPerUe.ThroughputUl getUl() {
+                    return ul;
+                }
+
+                /**
+                 * Set UL.
+                 *
+                 * @param ul Ul
+                 */
+                public void setUl(PDCPMeasReportPerUe.ThroughputUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String
+                toString() {
+                    return "PdcpThroughput{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class DataVol {
+                @JsonProperty("dl")
+                private PDCPMeasReportPerUe.DataVolDl dl;
+                @JsonProperty("ul")
+                private PDCPMeasReportPerUe.DataVolUl ul;
+
+                public DataVol() {
+                }
+
+                @JsonCreator
+                public DataVol(@JsonProperty("dl") PDCPMeasReportPerUe.DataVolDl dl,
+                               @JsonProperty("ul") PDCPMeasReportPerUe.DataVolUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                /**
+                 * Get DL.
+                 *
+                 * @return Dl
+                 */
+                public PDCPMeasReportPerUe.DataVolDl getDl() {
+                    return dl;
+                }
+
+                /**
+                 * Set DL.
+                 *
+                 * @param dl DL
+                 */
+                public void setDl(PDCPMeasReportPerUe.DataVolDl dl) {
+                    this.dl = dl;
+                }
+
+                /**
+                 * Get UL.
+                 *
+                 * @return Ul
+                 */
+                public PDCPMeasReportPerUe.DataVolUl getUl() {
+                    return ul;
+                }
+
+                /**
+                 * Set UL.
+                 *
+                 * @param ul Ul
+                 */
+                public void setUl(PDCPMeasReportPerUe.DataVolUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String
+                toString() {
+                    return "PdcpThroughput{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+
+            @JsonPropertyOrder({
+                    "dl",
+                    "ul"
+            })
+            @JsonIgnoreProperties(ignoreUnknown = true)
+            public static class PktLossRate {
+                @JsonProperty("dl")
+                PDCPMeasReportPerUe.PktLossRateDl dl;
+                @JsonProperty("ul")
+                PDCPMeasReportPerUe.PktLossRateUl ul;
+
+                public PktLossRate() {
+                }
+
+                @JsonCreator
+                public PktLossRate(@JsonProperty("dl") PDCPMeasReportPerUe.PktLossRateDl dl,
+                                   @JsonProperty("ul") PDCPMeasReportPerUe.PktLossRateUl ul) {
+                    this.dl = dl;
+                    this.ul = ul;
+                }
+
+                /**
+                 * Get DL.
+                 *
+                 * @return Dl
+                 */
+                public PDCPMeasReportPerUe.PktLossRateDl getDl() {
+                    return dl;
+                }
+
+                /**
+                 * Set DL.
+                 *
+                 * @param dl DL
+                 */
+                public void setDl(PDCPMeasReportPerUe.PktLossRateDl dl) {
+                    this.dl = dl;
+                }
+
+                /**
+                 * Get UL.
+                 *
+                 * @return Ul
+                 */
+                public PDCPMeasReportPerUe.PktLossRateUl getUl() {
+                    return ul;
+                }
+
+                /**
+                 * Set UL.
+                 *
+                 * @param ul Ul
+                 */
+                public void setUl(PDCPMeasReportPerUe.PktLossRateUl ul) {
+                    this.ul = ul;
+                }
+
+                @Override
+                public String toString() {
+                    return "PdcpPacketdelay{" +
+                            "dl=" + dl +
+                            ", ul=" + ul +
+                            '}';
+                }
+            }
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibSlice.java b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibSlice.java
new file mode 100644
index 0000000..f8cb470
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibSlice.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.entities;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+import java.util.Set;
+
+/**
+ * Created by dimitris on 7/22/17.
+ */
+@JsonPropertyOrder({
+        "Identifier",
+        "Description",
+        "UE-IDs",
+        "Links",
+        "ValidityPeriod",
+        "DesiredKPIs",
+        "DeliveredKPIs",
+        "RRMConfiguration"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RnibSlice {
+    @JsonProperty("Identifier")
+    private long sliceId;
+    @JsonProperty("Description")
+    private String description;
+    @JsonProperty("UE-IDs")
+    private Set<Long> ueID;
+    @JsonProperty("Links")
+    private Set<RnibLink> links;
+    @JsonProperty("ValidityPeriod")
+    private long validityPeriod;
+    @JsonProperty("DesiredKPIs")
+    private Object desiredKpis;
+    @JsonProperty("DeliveredKPIs")
+    private Object deliveredKpis;
+    @JsonProperty("RRMConfiguration")
+    private Object rrmConfiguration;
+
+    public long getSliceId() {
+        return sliceId;
+    }
+
+    public void setSliceId(long sliceId) {
+        this.sliceId = sliceId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Set<Long> getUeID() {
+        return ueID;
+    }
+
+    public void setUeID(Set<Long> ueID) {
+        this.ueID = ueID;
+    }
+
+    public Set<RnibLink> getLinks() {
+        return links;
+    }
+
+    public void setLinks(Set<RnibLink> links) {
+        this.links = links;
+    }
+
+    public long getValidityPeriod() {
+        return validityPeriod;
+    }
+
+    public void setValidityPeriod(long validityPeriod) {
+        this.validityPeriod = validityPeriod;
+    }
+
+    public Object getDesiredKpis() {
+        return desiredKpis;
+    }
+
+    public void setDesiredKpis(Object desiredKpis) {
+        this.desiredKpis = desiredKpis;
+    }
+
+    public Object getDeliveredKpis() {
+        return deliveredKpis;
+    }
+
+    public void setDeliveredKpis(Object deliveredKpis) {
+        this.deliveredKpis = deliveredKpis;
+    }
+
+    public Object getRrmConfiguration() {
+        return rrmConfiguration;
+    }
+
+    public void setRrmConfiguration(Object rrmConfiguration) {
+        this.rrmConfiguration = rrmConfiguration;
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibUe.java b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibUe.java
new file mode 100644
index 0000000..714182c
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/RnibUe.java
@@ -0,0 +1,392 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.entities;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.HostId;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ENBUES1APID;
+import org.onosproject.xran.asn1lib.api.MMEUES1APID;
+import org.onosproject.xran.asn1lib.pdu.RRCMeasConfig;
+import org.onosproject.xran.asn1lib.pdu.UECapabilityInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Objects;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.onosproject.net.HostId.hostId;
+
+/**
+ * R-NIB UE and its properties.
+ */
+@JsonPropertyOrder({
+        "Identifier",
+        "Context-IDs",
+        "RAN-ID",
+        "State",
+        "Capability",
+        "MeasurementConfiguration"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RnibUe {
+    @JsonIgnore
+    private static final Logger log =
+            LoggerFactory.getLogger(RnibUe.class);
+
+    @JsonProperty("Identifier")
+    private Long id;
+    @JsonProperty("Context-IDs")
+    private ContextIds contextIds = new ContextIds();
+    @JsonProperty("RAN-ID")
+    private CRNTI crnti;
+    @JsonProperty("State")
+    private State state = State.ACTIVE;
+    @JsonProperty("Capability")
+    private UECapabilityInfo capability;
+    @JsonProperty("MeasurementConfiguration")
+    private RRCMeasConfig measConfig;
+    @JsonIgnore
+    private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+
+    /**
+     * Convert Host ID to UE ID.
+     *
+     * @param hostId hostID
+     * @return Long UE ID
+     */
+    public static Long hostIdtoUEId(HostId hostId) {
+        String mac = hostId.mac().toString();
+        mac = mac.replace(":", "");
+        return Long.parseLong(mac, 16);
+    }
+
+    /**
+     * Get timer.
+     *
+     * @return Timer
+     */
+    public ScheduledExecutorService getExecutor() {
+        return executor;
+    }
+
+    /**
+     * Set executor.
+     *
+     * @param executor executor
+     */
+    public void setExecutor(ScheduledExecutorService executor) {
+        this.executor.shutdown();
+        this.executor = executor;
+    }
+
+    /**
+     * Get CRNTI.
+     *
+     * @return CRNTI
+     */
+    public CRNTI getCrnti() {
+        return crnti;
+    }
+
+    /**
+     * Set CRNTI.
+     *
+     * @param crnti CRNTI
+     */
+    public void setCrnti(CRNTI crnti) {
+        this.crnti = crnti;
+    }
+
+    /**
+     * Get Host ID.
+     *
+     * @return HostId
+     */
+    @JsonIgnore
+    public HostId getHostId() {
+        try {
+            String text = Long.toHexString(this.id),
+                    res = "";
+            int charsLeft = 12 - text.length();
+            if (charsLeft > 0) {
+                res += Stream.generate(() -> "0").limit(charsLeft).collect(Collectors.joining(""));
+            } else if (charsLeft < 0) {
+                return null;
+            }
+            res += text;
+
+            String insert = ":";
+            int period = 2;
+
+            StringBuilder builder = new StringBuilder(
+                    res.length() + insert.length() * (res.length() / period) + 1);
+
+            int index = 0;
+            String prefix = "";
+            while (index < res.length()) {
+                // Don't putPrimaryLink the insert in the very first iteration.
+                // This is easier than appending it *after* each substring
+                builder.append(prefix);
+                prefix = insert;
+                builder.append(res.substring(index,
+                        Math.min(index + period, res.length())));
+                index += period;
+            }
+
+            return hostId(MacAddress.valueOf(builder.toString()));
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Get RXMeasConfig Report.
+     *
+     * @return RXSigMeasConfig
+     */
+    public RRCMeasConfig getMeasConfig() {
+        return measConfig;
+    }
+
+    /**
+     * Set RXMeasConfig Report.
+     *
+     * @param measConfig RXSigMeasConfig
+     */
+    public void setMeasConfig(RRCMeasConfig measConfig) {
+        this.measConfig = measConfig;
+    }
+
+    /**
+     * Get UE Capability Info.
+     *
+     * @return UECapabilityInfo
+     */
+    public UECapabilityInfo getCapability() {
+        return capability;
+    }
+
+    /**
+     * Set UE Capability Info.
+     *
+     * @param capability UECapabilityInfo
+     */
+    public void setCapability(UECapabilityInfo capability) {
+        this.capability = capability;
+    }
+
+    /**
+     * Get State.
+     *
+     * @return State
+     */
+    public State getState() {
+        return state;
+    }
+
+    /**
+     * Set State.
+     *
+     * @param state State
+     */
+    public void setState(State state) {
+        this.state = state;
+    }
+
+    /**
+     * Get UE ID.
+     *
+     * @return Long UE ID
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * Set UE ID.
+     *
+     * @param id Long UE ID
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public ContextIds getContextIds() {
+        return contextIds;
+    }
+
+    public void setContextIds(ContextIds contextIds) {
+        this.contextIds = contextIds;
+    }
+
+    @Override
+    public String toString() {
+        return "RnibUe{" +
+                "id=" + id +
+                ", contextIds=" + contextIds +
+                ", crnti=" + crnti +
+                ", state=" + state +
+                ", capability=" + capability +
+                ", measConfig=" + measConfig +
+                '}';
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        RnibUe rnibUe = (RnibUe) o;
+        return Objects.equals(id, rnibUe.id);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id);
+    }
+
+
+    /**
+     * Enum of State of UE.
+     */
+    public enum State {
+        ACTIVE {
+            @Override
+            public String toString() {
+                return "ACTIVE";
+            }
+        },
+        IDLE {
+            @Override
+            public String toString() {
+                return "IDLE";
+            }
+        }
+    }
+
+    /**
+     * Context IDs.
+     */
+    @JsonPropertyOrder({
+            "IMSI",
+            "ENBUES1APID",
+            "MMEUES1APID",
+    })
+    @JsonIgnoreProperties(ignoreUnknown = true)
+    public static class ContextIds {
+        @JsonProperty("IMSI")
+        private String imsi = "";
+        @JsonProperty("ENBUES1APID")
+        private ENBUES1APID enbS1apId;
+        @JsonProperty("MMEUES1APID")
+        private MMEUES1APID mmeS1apId;
+
+        public ContextIds() {
+        }
+
+        @JsonCreator
+        public ContextIds(
+                @JsonProperty("ENBUES1APID") ENBUES1APID enbS1apId,
+                @JsonProperty("MMEUES1APID") MMEUES1APID mmeS1apId
+        ) {
+            this.enbS1apId = enbS1apId;
+            this.mmeS1apId = mmeS1apId;
+        }
+
+        public ContextIds(String imsi, ENBUES1APID enbS1apId, MMEUES1APID mmeS1apId) {
+            this.imsi = imsi;
+            this.enbS1apId = enbS1apId;
+            this.mmeS1apId = mmeS1apId;
+        }
+
+        /**
+         * Get MMEUES1APID.
+         *
+         * @return MMEUES1APID
+         */
+        public MMEUES1APID getMmeS1apId() {
+            return mmeS1apId;
+        }
+
+        /**
+         * Set MMEUES1APID.
+         *
+         * @param mmeS1apId MMEUES1APID
+         */
+        public void setMmeS1apId(MMEUES1APID mmeS1apId) {
+            this.mmeS1apId = mmeS1apId;
+        }
+
+        /**
+         * Get ENBUES1APID.
+         *
+         * @return ENBUES1APID
+         */
+        public ENBUES1APID getEnbS1apId() {
+            return enbS1apId;
+        }
+
+        /**
+         * Set ENBUES1APID.
+         *
+         * @param enbS1apId ENBUES1APID
+         */
+        public void setEnbS1apId(ENBUES1APID enbS1apId) {
+            this.enbS1apId = enbS1apId;
+        }
+
+        /**
+         * Get IMSI.
+         *
+         * @return IMSI
+         */
+        public String getImsi() {
+            return imsi;
+        }
+
+        /**
+         * Set IMSI.
+         *
+         * @param imsi IMSI
+         */
+        public void setImsi(String imsi) {
+            this.imsi = imsi;
+        }
+
+        @Override
+        public String toString() {
+            return "ContextIds{" +
+                    "imsi='" + imsi + '\'' +
+                    ", enbS1apId=" + enbS1apId +
+                    ", mmeS1apId=" + mmeS1apId +
+                    '}';
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/entities/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/package-info.java
new file mode 100644
index 0000000..0817620
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/entities/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/22/17.
+ */
+package org.onosproject.xran.impl.entities;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/ContextUpdateHandler.java b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/ContextUpdateHandler.java
new file mode 100644
index 0000000..2209825
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/ContextUpdateHandler.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.identifiers;
+
+import org.onosproject.xran.asn1lib.pdu.HOComplete;
+import org.onosproject.xran.asn1lib.pdu.UEAdmissionStatus;
+import org.onosproject.xran.asn1lib.pdu.UEContextUpdate;
+
+/**
+ * Class to handle UE Context Update packet.
+ */
+public class ContextUpdateHandler {
+    private UEContextUpdate contextUpdate;
+    private UEAdmissionStatus admissionStatus;
+    private HOComplete hoComplete;
+
+    /**
+     * Get Context Update.
+     * @return UEContextUpdate
+     */
+    public UEContextUpdate getContextUpdate() {
+        return contextUpdate;
+    }
+
+    /**
+     * Set Context Update.
+     * @param contextUpdate UEContextUpdate
+     * @return boolean to check context update was for admissionStatus packet or HOComplete packet
+     */
+    public boolean setContextUpdate(UEContextUpdate contextUpdate) {
+        synchronized (this) {
+            this.contextUpdate = contextUpdate;
+
+            return admissionStatus != null || hoComplete != null;
+        }
+    }
+
+    /**
+     * Get UEAdmissionStatus.
+     * @return UEAdmissionStatus
+     */
+    public UEAdmissionStatus getAdmissionStatus() {
+        return admissionStatus;
+    }
+
+    /**
+     * Set UEAdmissionStatus.
+     * @param admissionStatus UEAdmissionStatus
+     * @return boolean contextUpdate exists or not
+     */
+    public boolean setAdmissionStatus(UEAdmissionStatus admissionStatus) {
+        synchronized (this) {
+            this.admissionStatus = admissionStatus;
+
+            return contextUpdate != null;
+        }
+    }
+
+    /**
+     * Get HOComplete.
+     * @return HOComplete
+     */
+    public HOComplete getHoComplete() {
+        return hoComplete;
+    }
+
+    /**
+     * Set HOComplete.
+     * @param hoComplete HOComplete
+     * @return boolean contextUpdate exists or not
+     */
+    public boolean setHoComplete(HOComplete hoComplete) {
+        synchronized (this) {
+            this.hoComplete = hoComplete;
+
+            return contextUpdate != null;
+        }
+    }
+
+    /**
+     * Reset the values of the variables.
+     *
+     */
+    public void reset() {
+        synchronized (this) {
+            this.hoComplete = null;
+            this.admissionStatus = null;
+            this.contextUpdate = null;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "ContextUpdateHandler{" +
+                "contextUpdate=" + (contextUpdate != null) +
+                ", admissionStatus=" + (admissionStatus != null) +
+                ", hoComplete=" + (hoComplete != null) +
+                '}';
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/EcgiCrntiPair.java b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/EcgiCrntiPair.java
new file mode 100644
index 0000000..7e78bfa
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/EcgiCrntiPair.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.identifiers;
+
+import com.google.common.base.Objects;
+import javafx.util.Pair;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+
+/**
+ * Class to maintain pair of ECGI and CRNTI.
+ */
+public class EcgiCrntiPair extends Pair<ECGI, CRNTI> {
+
+    /**
+     * Creates a new pair.
+     *
+     * @param key   The key for this pair
+     * @param value The value to use for this pair
+     */
+    public EcgiCrntiPair(ECGI key, CRNTI value) {
+        super(key, value);
+    }
+
+    /**
+     * Return a new EcgiCrntiPair.
+     *
+     * @param key ECGI
+     * @param value CRNTI
+     * @return EcgiCrntiPair
+     */
+    public static EcgiCrntiPair valueOf(ECGI key, CRNTI value) {
+        return new EcgiCrntiPair(key, value);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(getKey(), getValue());
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof EcgiCrntiPair) {
+            return ((EcgiCrntiPair) o).getKey().equals(getKey()) &&
+                    ((EcgiCrntiPair) o).getValue().equals(getValue());
+        }
+        return super.equals(o);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/LinkId.java b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/LinkId.java
new file mode 100644
index 0000000..a439461
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/LinkId.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.identifiers;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibUe;
+
+/**
+ * Class for LinkId.
+ */
+@JsonPropertyOrder({
+        "ECGI",
+        "UEID"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public final class LinkId {
+    @JsonIgnore
+    private RnibCell cell;
+    @JsonIgnore
+    private RnibUe ue;
+
+    private LinkId(RnibCell cell, RnibUe ue) {
+        this.cell = cell;
+        this.ue = ue;
+    }
+
+    /**
+     * Create new LinkId.
+     * @param cell Cell
+     * @param ue UE
+     * @return new LinkId
+     */
+    public static LinkId valueOf(RnibCell cell, RnibUe ue) {
+        return new LinkId(cell, ue);
+    }
+
+    /**
+     * Create new LinkID with ECGI and UE ID given.
+     * @param ecgi ECGI of new cell
+     * @param ueId UE ID of new UE
+     * @return LinkId
+     */
+    public static LinkId valueOf(ECGI ecgi, Long ueId) {
+        RnibCell cell = new RnibCell();
+        RnibUe ue = new RnibUe();
+
+        cell.setEcgi(ecgi);
+        ue.setId(ueId);
+        return new LinkId(cell, ue);
+    }
+
+    /**
+     * Get ECGI.
+     * @return ECGI
+     */
+    @JsonProperty("ECGI")
+    public ECGI getEcgi() {
+        return cell.getEcgi();
+    }
+
+    /**
+     * Set ECGI.
+     * @param sourceId ECGI
+     */
+    @JsonProperty("ECGI")
+    public void setEcgi(ECGI sourceId) {
+        cell.setEcgi(sourceId);
+    }
+
+    /**
+     * Get UE ID.
+     * @return long UE ID
+     */
+    @JsonProperty("UEID")
+    public Long getUeId() {
+        return ue.getId();
+    }
+
+    /**
+     * Set UE ID.
+     * @param destinationId long UE ID
+     */
+    @JsonProperty("UEID")
+    public void setUeId(Long destinationId) {
+        ue.setId(destinationId);
+    }
+
+    /**
+     * Get Cell.
+     * @return Cell
+     */
+    @JsonIgnore
+    public RnibCell getCell() {
+        return cell;
+    }
+
+    /**
+     * Set Cell.
+     * @param cell Cell
+     */
+    @JsonIgnore
+    public void setCell(RnibCell cell) {
+        this.cell = cell;
+    }
+
+    /**
+     * Get UE.
+     * @return UE
+     */
+    @JsonIgnore
+    public RnibUe getUe() {
+        return ue;
+    }
+
+    /**
+     * Set UE.
+     * @param ue UE
+     */
+    @JsonIgnore
+    public void setUe(RnibUe ue) {
+        this.ue = ue;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#equals()
+     */
+    @Override
+    public boolean equals(Object o) {
+        return this == o ||
+                o != null &&
+                        o instanceof LinkId &&
+                        cell.getEcgi().equals(((LinkId) o).cell.getEcgi()) &&
+                        ue.getId().equals(((LinkId) o).ue.getId());
+
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        int result = cell.getEcgi().hashCode();
+        result = 31 * result + ue.getId().hashCode();
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\n")
+                .append(cell != null ? "\"cell\":" + cell : "")
+                .append(ue != null ? ",\n\"ue\":" + ue : "")
+                .append("\n}\n");
+        return sb.toString();
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/package-info.java
new file mode 100644
index 0000000..f5227c7
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/identifiers/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/22/17.
+ */
+package org.onosproject.xran.impl.identifiers;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/package-info.java
new file mode 100644
index 0000000..66ce0b7
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/23/17.
+ */
+package org.onosproject.xran.impl;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/providers/CellDeviceProvider.java b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/CellDeviceProvider.java
new file mode 100644
index 0000000..33b49d6
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/CellDeviceProvider.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.providers;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranDeviceListener;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.slf4j.Logger;
+
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.xran.impl.entities.RnibCell.uri;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Cell device provider.
+ */
+@Component(immediate = true)
+public class CellDeviceProvider extends AbstractProvider implements DeviceProvider {
+
+    private static final Logger log = getLogger(CellDeviceProvider.class);
+    private final InternalDeviceListener listener = new InternalDeviceListener();
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceProviderRegistry providerRegistry;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected XranService controller;
+    private DeviceProviderService providerService;
+
+    public CellDeviceProvider() {
+        super(new ProviderId("xran", "org.onosproject.providers.cell"));
+    }
+
+    @Activate
+    public void activate() {
+        providerService = providerRegistry.register(this);
+        controller.addListener(listener);
+
+        log.info("XRAN Device Provider Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        controller.removeListener(listener);
+        providerRegistry.unregister(this);
+
+        providerService = null;
+        log.info("XRAN Device Provider Stopped");
+    }
+
+    @Override
+    public void triggerProbe(DeviceId deviceId) {
+
+    }
+
+    @Override
+    public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+
+    }
+
+    @Override
+    public boolean isReachable(DeviceId deviceId) {
+        return true;
+    }
+
+    @Override
+    public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
+
+    }
+
+    /**
+     * Internal device listener.
+     */
+    private class InternalDeviceListener implements XranDeviceListener {
+
+        @Override
+        public void deviceAdded(RnibCell cell) {
+            if (providerService == null) {
+                return;
+            }
+
+            // use ECGI as device ID URI
+            DeviceId id = deviceId(uri(cell.getEcgi()));
+
+            ChassisId cId = new ChassisId(id.hashCode());
+
+            Device.Type type = Device.Type.OTHER;
+            SparseAnnotations annotations = DefaultAnnotations.builder()
+                    .set(AnnotationKeys.NAME, "eNodeB " + cell.getEcgi().getEUTRANcellIdentifier())
+                    .set(AnnotationKeys.PROTOCOL, "SCTP")
+                    .set(AnnotationKeys.CHANNEL_ID, "xxx")
+                    .set(AnnotationKeys.MANAGEMENT_ADDRESS, "127.0.0.1")
+                    .set(AnnotationKeys.UI_TYPE, "basestation")
+                    .build();
+
+            DeviceDescription descBase =
+                    new DefaultDeviceDescription(id.uri(), type,
+                            "xran", "0.1", "0.1", id.uri().toString(),
+                            cId);
+            DeviceDescription desc = new DefaultDeviceDescription(descBase, annotations);
+
+            providerService.deviceConnected(id, desc);
+        }
+
+        @Override
+        public void deviceRemoved(DeviceId id) {
+            providerService.deviceDisconnected(id);
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/providers/UeProvider.java b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/UeProvider.java
new file mode 100644
index 0000000..e618e3b
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/UeProvider.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.providers;
+
+import com.google.common.collect.Sets;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.HostLocation;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.host.DefaultHostDescription;
+import org.onosproject.net.host.HostProvider;
+import org.onosproject.net.host.HostProviderRegistry;
+import org.onosproject.net.host.HostProviderService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranHostListener;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.impl.entities.RnibUe;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.xran.impl.entities.RnibCell.uri;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * UE Provider.
+ */
+@Component(immediate = true)
+public class UeProvider extends AbstractProvider implements HostProvider {
+
+    private static final Logger log = getLogger(UeProvider.class);
+    private final InternalHostListener listener = new InternalHostListener();
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private HostProviderRegistry providerRegistry;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private XranService controller;
+    private HostProviderService providerService;
+
+    public UeProvider() {
+        super(new ProviderId("xran", "org.onosproject.providers.ue"));
+    }
+
+    @Activate
+    public void activate() {
+        providerService = providerRegistry.register(this);
+        controller.addListener(listener);
+
+        log.info("XRAN Host Provider Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        controller.removeListener(listener);
+        providerRegistry.unregister(this);
+
+        providerService = null;
+        log.info("XRAN Host Provider Stopped");
+    }
+
+    @Override
+    public void triggerProbe(Host host) {
+
+    }
+
+    /**
+     * Internal host listener.
+     */
+    class InternalHostListener implements XranHostListener {
+
+        @Override
+        public void hostAdded(RnibUe ue, Set<ECGI> ecgiSet) {
+            if (providerService == null) {
+                return;
+            }
+
+            if (ue == null) {
+                log.error("UE is not found");
+                return;
+            }
+
+            try {
+                Set<HostLocation> hostLocations = Sets.newConcurrentHashSet();
+
+                ecgiSet.forEach(ecgi -> hostLocations
+                        .add(new HostLocation(deviceId(uri(ecgi)),
+                                PortNumber.portNumber(0), 0)));
+
+                SparseAnnotations annotations = DefaultAnnotations.builder()
+                        .set(AnnotationKeys.NAME, "UE " + ue.getId())
+                        .set(AnnotationKeys.UI_TYPE, "mobile")
+                        .build();
+
+                // Host ID is calculated from UE ID with some hacky function to represent a MAC address.
+                DefaultHostDescription desc = new DefaultHostDescription(
+                        ue.getHostId().mac(),
+                        VlanId.vlanId(VlanId.UNTAGGED),
+                        hostLocations,
+                        Sets.newConcurrentHashSet(),
+                        true,
+                        annotations
+                );
+
+                providerService.hostDetected(ue.getHostId(), desc, false);
+            } catch (Exception e) {
+                log.warn(e.getMessage());
+                e.printStackTrace();
+            }
+        }
+
+        @Override
+        public void hostRemoved(HostId id) {
+            providerService.hostVanished(id);
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/providers/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/package-info.java
new file mode 100644
index 0000000..d4679ba
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/providers/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/27/17.
+ */
+package org.onosproject.xran.impl.providers;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/CellWebResource.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/CellWebResource.java
new file mode 100644
index 0000000..81ada71
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/CellWebResource.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+package org.onosproject.xran.impl.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PATCH;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Cell web resource.
+ */
+@Path("cell")
+public class CellWebResource extends AbstractWebResource {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(CellWebResource.class);
+
+    private XranStore xranStore;
+    private XranService xranService;
+
+    public CellWebResource() {
+        xranStore = get(XranStore.class);
+        xranService = get(XranService.class);
+    }
+
+    /**
+     * Lists the cell with {cellid}.
+     *
+     * @param eciHex EutranCellIdentifier in binary
+     * @return Response
+     */
+    @GET
+    @Path("{cellid}")
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+    })
+    public Response getCell(@PathParam("cellid") String eciHex) {
+        return xranStore.getCell(eciHex).map(cell -> {
+            try {
+                JsonNode jsonNode = mapper().valueToTree(cell);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_OK,
+                        jsonNode
+                );
+
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+                e.printStackTrace();
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }).orElse(ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_NOT_FOUND,
+                "Not Found",
+                "Cell with " + eciHex + " was not found"
+        ));
+    }
+
+    /**
+     * Modify the RRMConfig parameters of the cell.
+     *
+     * @param eciHex EutranCellIdentifier in binary
+     * @param stream Parameters that you want to modify
+     * @return Response
+     */
+    @PATCH
+    @Path("{cellid}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 408, message = "HTTP_CLIENT_TIMEOUT"),
+            @ApiResponse(code = 400, message = "HTTP_BAD_REQUEST"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+
+    })
+    public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
+        return xranStore.getCell(eciHex).map(cell -> {
+            try {
+                ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+
+                JsonNode rrmConf = jsonTree.path("RRMConf");
+                if (!rrmConf.isMissingNode()) {
+                    xranStore.modifyCellRrmConf(cell, rrmConf);
+
+                    return xranService.sendModifiedRrm(cell.getRrmConfig())
+                            .flatMap(queue -> {
+                                try {
+                                    return Optional.ofNullable(queue.poll(xranService
+                                            .getNorthboundTimeout(), TimeUnit.MILLISECONDS));
+                                } catch (InterruptedException e) {
+                                    log.error(ExceptionUtils.getFullStackTrace(e));
+                                    return Optional.empty();
+                                }
+                            }).map(p ->
+                                    ResponseHelper.getResponse(
+                                            mapper(),
+                                            HttpURLConnection.HTTP_OK,
+                                            "Handoff Response",
+                                            p
+                                    )
+                            ).orElse(
+                                    ResponseHelper.getResponse(
+                                            mapper(),
+                                            HttpURLConnection.HTTP_CLIENT_TIMEOUT,
+                                            "Handoff Timeout",
+                                            "eNodeB did not send a HOComplete/HOFailure on time"
+                                    )
+                            );
+                }
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_BAD_REQUEST,
+                        "Bad Request",
+                        "The command you specified is not implemented or doesn't exist. We support " +
+                                "RRMConf commands."
+                );
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }).orElse(ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_NOT_FOUND,
+                "Not Found",
+                "Cell " + eciHex + " was not found"
+        ));
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/LinkWebResource.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/LinkWebResource.java
new file mode 100644
index 0000000..1c91bac
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/LinkWebResource.java
@@ -0,0 +1,519 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+package org.onosproject.xran.impl.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.xran.XranService;
+import org.onosproject.xran.XranStore;
+import org.onosproject.xran.asn1lib.ber.types.BerInteger;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibLink;
+import org.onosproject.xran.impl.entities.RnibUe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.PATCH;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Link web resource.
+ */
+@Path("links")
+public class LinkWebResource extends AbstractWebResource {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(LinkWebResource.class);
+
+    private XranStore xranStore;
+    private XranService xranService;
+
+    public LinkWebResource() {
+        xranStore = get(XranStore.class);
+        xranService = get(XranService.class);
+    }
+
+    /**
+     * List all the links originating or terminating at cell/UE OR list the link connecting between cell and UE.
+     *
+     * @param eciHex EutranCellIdentifier in binary
+     * @param ue     UE ID
+     * @return Response
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+    })
+    public Response getLinksBetween(@DefaultValue("") @QueryParam("cell") String eciHex,
+                                    @DefaultValue("-1") @QueryParam("ue") long ue) {
+        List<RnibLink> list = Lists.newArrayList();
+        if (!eciHex.isEmpty() && ue != -1) {
+            xranStore.getLink(eciHex, ue).ifPresent(list::add);
+        } else if (!eciHex.isEmpty()) {
+            list.addAll(xranStore.getLinks(eciHex));
+        } else if (ue != -1) {
+            list.addAll(xranStore.getLinks(ue));
+        } else {
+            list.addAll(xranStore.getLinks());
+        }
+
+        if (list.size() > 0) {
+            try {
+                JsonNode jsonNode = mapper().valueToTree(list);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_OK,
+                        jsonNode
+                );
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+                e.printStackTrace();
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_NOT_FOUND,
+                "Not Found",
+                "Specified links not found"
+        );
+    }
+
+    /**
+     * Modify the link.
+     *
+     * @param src    CELL ECI in binary
+     * @param dst    UE ID
+     * @param stream Parameter on basis of which link is to be modified
+     * @return Response
+     */
+    @PATCH
+    @Path("{src},{dst}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 501, message = "HTTP_NOT_IMPLEMENTED"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND"),
+            @ApiResponse(code = 400, message = "HTTP_BAD_REQUEST"),
+            @ApiResponse(code = 408, message = "HTTP_CLIENT_TIMEOUT")
+    })
+    public Response patchLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
+        return xranStore.getLink(src, dst).map(link -> {
+            try {
+                ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+
+                // Modify link based on Type
+                JsonNode type = jsonTree.path("type");
+                if (!type.isMissingNode()) {
+                    RnibLink.Type anEnum = RnibLink.Type.getEnum(type.asText());
+                    return handleTypeChange(link, anEnum);
+                }
+
+                // Modify link based on traffic percent
+                JsonNode trafficpercent = jsonTree.path("trafficpercent");
+                if (!trafficpercent.isMissingNode()) {
+                    return handleTrafficChange(link, trafficpercent);
+                }
+
+                // Modify link based on RRMConf
+                JsonNode rrmConf = jsonTree.path("RRMConf");
+                if (!rrmConf.isMissingNode()) {
+                    return handleRrmChange(link, rrmConf);
+                }
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_NOT_IMPLEMENTED,
+                        "Not Implemented",
+                        "The command you specified is not implemented or doesn't exist. We support " +
+                                "type/RRMConf/traficpercent commands."
+                );
+
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+                e.printStackTrace();
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }).orElse(ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_NOT_FOUND,
+                "Not Found",
+                "Link not found use POST request"
+        ));
+    }
+
+    /**
+     * Create link based on Type of the link.
+     *
+     * @param src    CELL ECI in binary
+     * @param dst    UE ID
+     * @param stream LinkType
+     * @return Response
+     */
+    @POST
+    @Path("{src},{dst}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 501, message = "HTTP_NOT_IMPLEMENTED"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND"),
+            @ApiResponse(code = 400, message = "HTTP_BAD_REQUEST"),
+            @ApiResponse(code = 408, message = "HTTP_CLIENT_TIMEOUT"),
+    })
+    public Response postLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
+        Optional<RnibCell> cellOptional = xranStore.getCell(src);
+        Optional<RnibUe> ueOptional = xranStore.getUe(dst);
+
+        if (!cellOptional.isPresent()) {
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_NOT_FOUND,
+                    "Not Found",
+                    "Cell " + src + " was not found"
+            );
+        }
+
+        if (!ueOptional.isPresent()) {
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_NOT_FOUND,
+                    "Not Found",
+                    "Ue with " + dst + " was not found"
+            );
+        }
+
+        if (xranStore.getLink(cellOptional.get().getEcgi(), ueOptional.get().getId()) != null) {
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_BAD_REQUEST,
+                    "Bad Request",
+                    "Link already exists use PATCH to modify"
+            );
+        }
+
+        try {
+            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+
+            JsonNode type = jsonTree.path("type");
+
+            RnibLink link = new RnibLink(cellOptional.get(), ueOptional.get());
+            // store it as non-serving when creating link
+            xranStore.storeLink(link);
+            if (!type.isMissingNode()) {
+                return handleTypeChange(link, RnibLink.Type.getEnum(type.asText()));
+            }
+
+            JsonNode trafficpercent = jsonTree.path("trafficpercent");
+            if (!trafficpercent.isMissingNode()) {
+                return handleTrafficChange(link, trafficpercent);
+            }
+
+            JsonNode rrmConf = jsonTree.path("RRMConf");
+            if (!rrmConf.isMissingNode()) {
+                return handleRrmChange(link, rrmConf);
+            }
+
+        } catch (Exception e) {
+            String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+            log.error(fullStackTrace);
+            e.printStackTrace();
+
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_INTERNAL_ERROR,
+                    "Exception",
+                    fullStackTrace
+            );
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_BAD_REQUEST,
+                "Bad Request",
+                "The command you specified is not implemented " +
+                        "or doesn't exist. We support " +
+                        "type/RRMConf/traficpercent commands."
+        );
+    }
+
+
+    /**
+     * Change link based on type of the link.
+     *
+     * @param link    Link
+     * @param newType LinkType
+     * @return Response
+     * @throws InterruptedException Interrupted queue
+     */
+
+    private Response handleTypeChange(RnibLink link, RnibLink.Type newType)
+            throws InterruptedException {
+        if (newType.equals(RnibLink.Type.SERVING_PRIMARY)) {
+            switch (link.getType()) {
+                case SERVING_PRIMARY: {
+                    return ResponseHelper.getResponse(
+                            mapper(),
+                            HttpURLConnection.HTTP_BAD_REQUEST,
+                            "Bad Request",
+                            "Link is already a primary link"
+                    );
+                }
+                case SERVING_SECONDARY_CA:
+                case SERVING_SECONDARY_DC:
+                case NON_SERVING: {
+                    List<RnibLink> linksByUeId = xranStore
+                            .getLinks(link.getLinkId().getUeId());
+
+                    return linksByUeId.stream()
+                            .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
+                            .findFirst().map(primaryLink -> xranService.sendHoRequest(link, primaryLink)
+                                    .flatMap(q -> {
+                                        try {
+                                            return Optional.ofNullable(q.poll(xranService
+                                                    .getNorthboundTimeout(), TimeUnit.MILLISECONDS));
+                                        } catch (InterruptedException e) {
+                                            log.error(ExceptionUtils.getFullStackTrace(e));
+                                            return Optional.empty();
+                                        }
+                                    }).map(poll ->
+                                            ResponseHelper.getResponse(
+                                                    mapper(),
+                                                    HttpURLConnection.HTTP_OK,
+                                                    "Handoff Response",
+                                                    poll
+                                            )
+                                    ).orElse(
+                                            ResponseHelper.getResponse(
+                                                    mapper(),
+                                                    HttpURLConnection.HTTP_CLIENT_TIMEOUT,
+                                                    "Handoff Timeout",
+                                                    "eNodeB did not send a HOComplete/HOFailure on time"
+                                            )
+                                    )
+                            )
+                            .orElseGet(
+                                    () -> {
+                                        link.setType(RnibLink.Type.SERVING_PRIMARY);
+                                        return ResponseHelper.getResponse(
+                                                mapper(),
+                                                HttpURLConnection.HTTP_OK,
+                                                "OK",
+                                                "Link set to primary"
+                                        );
+                                    }
+                            );
+                }
+                default:
+            }
+        } else if (newType.equals(RnibLink.Type.NON_SERVING)) {
+            switch (link.getType()) {
+                case NON_SERVING: {
+                    return ResponseHelper.getResponse(
+                            mapper(),
+                            HttpURLConnection.HTTP_BAD_REQUEST,
+                            "Bad Request",
+                            "Link is already a primary link"
+                    );
+                }
+                case SERVING_PRIMARY: {
+                    return ResponseHelper.getResponse(
+                            mapper(),
+                            HttpURLConnection.HTTP_BAD_REQUEST,
+                            "Bad Request",
+                            "Cannot modify a primary link"
+                    );
+                }
+                case SERVING_SECONDARY_CA:
+                case SERVING_SECONDARY_DC: {
+                    if (xranService.sendScellDelete(link)) {
+                        return ResponseHelper.getResponse(
+                                mapper(),
+                                HttpURLConnection.HTTP_OK,
+                                "OK",
+                                "Link set to non-serving"
+                        );
+                    } else {
+                        return ResponseHelper.getResponse(
+                                mapper(),
+                                HttpURLConnection.HTTP_NOT_FOUND,
+                                "Not Found",
+                                "Could not find cell config report to construct Scell Delete"
+                        );
+                    }
+                }
+                default:
+            }
+        } else if (newType.equals(RnibLink.Type.SERVING_SECONDARY_CA)) {
+            switch (link.getType()) {
+                case SERVING_PRIMARY: {
+                    return ResponseHelper.getResponse(
+                            mapper(),
+                            HttpURLConnection.HTTP_BAD_REQUEST,
+                            "Bad Request",
+                            "Cannot modify a primary link"
+                    );
+                }
+                case SERVING_SECONDARY_DC:
+                case NON_SERVING: {
+                    return xranService.sendScellAdd(link).flatMap(queue -> {
+                        try {
+                            return Optional.ofNullable(queue.poll(xranService
+                                    .getNorthboundTimeout(), TimeUnit.MILLISECONDS));
+                        } catch (InterruptedException e) {
+                            log.error(ExceptionUtils.getFullStackTrace(e));
+                            return Optional.empty();
+                        }
+                    }).map(poll ->
+                            ResponseHelper.getResponse(
+                                    mapper(),
+                                    HttpURLConnection.HTTP_OK,
+                                    "ScellAdd Response",
+                                    poll
+                            )
+                    ).orElse(
+                            ResponseHelper.getResponse(
+                                    mapper(),
+                                    HttpURLConnection.HTTP_CLIENT_TIMEOUT,
+                                    "ScellAdd Timeout",
+                                    "eNodeB did not send a ScellAddStatus on time"
+                            )
+                    );
+                }
+                case SERVING_SECONDARY_CA: {
+                    return ResponseHelper.getResponse(
+                            mapper(),
+                            HttpURLConnection.HTTP_BAD_REQUEST,
+                            "Bad Request",
+                            "Link is already a secondary CA link"
+                    );
+                }
+                default:
+            }
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_BAD_REQUEST,
+                "Bad Request",
+                "The command you specified is not implemented or doesn't exist."
+        );
+    }
+
+    /**
+     * Modify link based on the traffic percent.
+     *
+     * @param link           Link
+     * @param trafficpercent Traffic Percent of the link to be modified
+     * @return Response
+     */
+    private Response handleTrafficChange(RnibLink link, JsonNode trafficpercent) {
+        JsonNode jsonNode = trafficpercent.path("traffic-percent-dl");
+        if (!jsonNode.isMissingNode()) {
+            link.getTrafficPercent().setTrafficPercentDl(new BerInteger(jsonNode.asInt()));
+        }
+
+        jsonNode = trafficpercent.path("traffic-percent-ul");
+        if (!jsonNode.isMissingNode()) {
+            link.getTrafficPercent().setTrafficPercentUl(new BerInteger(jsonNode.asInt()));
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_OK,
+                "OK",
+                "Traffic Percent changed"
+        );
+    }
+
+    /**
+     * Modify link based on RRMConf parameters.
+     *
+     * @param link    Link
+     * @param rrmConf RRMConfig of the Link to be modified
+     * @return Response
+     * @throws InterruptedException Interrupted queue
+     */
+    private Response handleRrmChange(RnibLink link, JsonNode rrmConf) throws InterruptedException {
+        xranStore.modifyLinkRrmConf(link, rrmConf);
+
+        return xranService.sendModifiedRrm(link.getRrmParameters()).flatMap(queue -> {
+            try {
+                return Optional.ofNullable(queue.poll(xranService
+                        .getNorthboundTimeout(), TimeUnit.MILLISECONDS));
+            } catch (InterruptedException e) {
+                log.error(ExceptionUtils.getFullStackTrace(e));
+                return Optional.empty();
+            }
+        }).map(poll ->
+                ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_OK,
+                        "RRMConfig Response",
+                        poll
+                )
+        ).orElse(
+                ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_CLIENT_TIMEOUT,
+                        "RRMConfig Timeout",
+                        "eNodeB did not send a RRMConfingStatus on time"
+                )
+        );
+
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/NodeWebResource.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/NodeWebResource.java
new file mode 100644
index 0000000..6c74d95
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/NodeWebResource.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+package org.onosproject.xran.impl.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.xran.XranStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.HttpURLConnection;
+import java.util.List;
+
+/**
+ * Node web resource.
+ */
+@Path("nodes")
+public class NodeWebResource extends AbstractWebResource {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(NodeWebResource.class);
+
+    public NodeWebResource() {
+    }
+
+    /**
+     * List all the nodes in the R-NIB.
+     *
+     * @param type Type of node (cell/ue)
+     * @return Response
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+    })
+    public Response getNodes(@DefaultValue("") @QueryParam("type") String type) {
+        JsonNode jsonNode;
+        try {
+            List<? extends Object> nodes;
+            // List cell type of nodes or UE type of nodes.
+            if (StringUtils.isBlank(type)) {
+                nodes = get(XranStore.class).getNodes();
+            } else if (type.equals("cell")) {
+                nodes = get(XranStore.class).getCellNodes();
+            } else if (type.equals("ue")) {
+                nodes = get(XranStore.class).getUeNodes();
+            } else {
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_NOT_FOUND,
+                        "Not Found",
+                        "Type of node was not found"
+                );
+            }
+
+            if (nodes.size() == 0) {
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_NOT_FOUND,
+                        "Not Found",
+                        "No nodes found"
+                );
+            }
+
+            jsonNode = mapper().valueToTree(nodes);
+        } catch (Exception e) {
+            String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+            log.error(fullStackTrace);
+
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_INTERNAL_ERROR,
+                    "Exception",
+                    fullStackTrace
+            );
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_OK,
+                jsonNode
+        );
+    }
+
+    /**
+     * List the node with a specific node id.
+     *
+     * @param nodeid ID of the node
+     * @return Response
+     */
+    @GET
+    @Path("{nodeid}")
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+    })
+    public Response getNodeid(@PathParam("nodeid") String nodeid) {
+        Object node = get(XranStore.class).getNode(nodeid);
+
+        if (node != null) {
+            try {
+                JsonNode jsonNode = mapper().valueToTree(node);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_OK,
+                        jsonNode
+                );
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+                e.printStackTrace();
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }
+
+        return ResponseHelper.getResponse(
+                mapper(),
+                HttpURLConnection.HTTP_NOT_FOUND,
+                "Not Found",
+                "Node " + nodeid + " was not found"
+        );
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/ResponseHelper.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/ResponseHelper.java
new file mode 100644
index 0000000..0a3abad
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/ResponseHelper.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * Various types of responses.
+ */
+public final class ResponseHelper {
+
+    private ResponseHelper() {
+    }
+
+    public static Response getResponse(ObjectMapper mapper, int status, String title, String detail) {
+        ObjectNode rootNode = mapper.createObjectNode();
+
+        switch (status) {
+            case 200: {
+                ArrayNode data = rootNode.putArray("data");
+                ObjectNode addObject = data.addObject();
+                addObject.put("status", status);
+                addObject.put("title", title);
+                addObject.put("detail", detail);
+                return Response.status(status)
+                        .entity(rootNode.toString())
+                        .build();
+            }
+            case 400:
+            case 501:
+            case 408:
+            case 500:
+            case 404: {
+                ArrayNode errors = rootNode.putArray("errors");
+                ObjectNode addObject = errors.addObject();
+                addObject.put("status", status);
+                addObject.put("title", title);
+                addObject.put("detail", detail);
+                return Response.status(status)
+                        .entity(rootNode.toString())
+                        .build();
+            }
+            default:
+                return Response.noContent().build();
+        }
+    }
+
+    public static Response getResponse(ObjectMapper mapper, int status, JsonNode node) {
+        ObjectNode rootNode = mapper.createObjectNode();
+
+        switch (status) {
+            case 200:
+            case 400:
+            case 501:
+            case 408:
+            case 500:
+            case 404: {
+                ArrayNode data = rootNode.putArray("data");
+                data.add(node);
+                return Response.status(status)
+                        .entity(rootNode.toString())
+                        .build();
+            }
+            default:
+                return Response.noContent().build();
+        }
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/SliceWebResource.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/SliceWebResource.java
new file mode 100644
index 0000000..10fcc5e
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/SliceWebResource.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+package org.onosproject.xran.impl.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.xran.XranStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+
+/**
+ * Slice web resource.
+ */
+@Path("slice")
+public class SliceWebResource extends AbstractWebResource {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(SliceWebResource.class);
+
+    public SliceWebResource() {
+    }
+
+    /**
+     * List the slice with the given slice ID.
+     *
+     * @param sliceid ID of the slice
+     * @return Response
+     */
+    @GET
+    @Path("{sliceid}")
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 404, message = "HTTP_NOT_FOUND")
+    })
+    public Response getSlice(@PathParam("sliceid") long sliceid) {
+        return get(XranStore.class).getSlice(sliceid).map(slice -> {
+            try {
+                JsonNode jsonNode = mapper().valueToTree(slice);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_OK,
+                        jsonNode
+                );
+            } catch (Exception e) {
+                String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+                log.error(fullStackTrace);
+
+                return ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_INTERNAL_ERROR,
+                        "Exception",
+                        fullStackTrace
+                );
+            }
+        }).orElse(
+                ResponseHelper.getResponse(
+                        mapper(),
+                        HttpURLConnection.HTTP_NOT_FOUND,
+                        "Not Found",
+                        "Slice " + sliceid + " not found"
+                )
+        );
+    }
+
+    /**
+     * Create slice with the corresponding attributes.
+     *
+     * @param stream Attributes to create slice
+     * @return Response
+     */
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "HTTP_OK"),
+            @ApiResponse(code = 500, message = "HTTP_INTERNAL_ERROR"),
+            @ApiResponse(code = 501, message = "HTTP_NOT_IMPLEMENTED")
+    })
+    public Response postSlice(InputStream stream) {
+        try {
+//            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+//            get(XranStore.class).createSlice(jsonTree);
+
+            // FIXME: change when implemented
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_NOT_IMPLEMENTED,
+                    "Not Implemented",
+                    "POST Slice not implemented"
+            );
+        } catch (Exception e) {
+            String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
+            log.error(fullStackTrace);
+            e.printStackTrace();
+
+            return ResponseHelper.getResponse(
+                    mapper(),
+                    HttpURLConnection.HTTP_INTERNAL_ERROR,
+                    "Exception",
+                    fullStackTrace
+            );
+        }
+    }
+
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/XranWebApplication.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/XranWebApplication.java
new file mode 100644
index 0000000..add727d
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/XranWebApplication.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Sample REST API web application.
+ */
+public class XranWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(
+                LinkWebResource.class,
+                NodeWebResource.class,
+                CellWebResource.class,
+                SliceWebResource.class);
+    }
+}
diff --git a/apps/xran/src/main/java/org.onosproject.xran/impl/rest/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/package-info.java
new file mode 100644
index 0000000..7c5ca9a
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/impl/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/20/17.
+ */
+package org.onosproject.xran.impl.rest;
\ No newline at end of file
diff --git a/apps/xran/src/main/java/org.onosproject.xran/package-info.java b/apps/xran/src/main/java/org.onosproject.xran/package-info.java
new file mode 100644
index 0000000..6e177d0
--- /dev/null
+++ b/apps/xran/src/main/java/org.onosproject.xran/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Created by dimitris on 7/20/17.
+ */
+package org.onosproject.xran;
diff --git a/apps/xran/src/main/webapp/WEB-INF/web.xml b/apps/xran/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..724584c
--- /dev/null
+++ b/apps/xran/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-present Open Networking Foundation
+  ~
+  ~ 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.
+  -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         id="ONOS" version="2.5">
+    <display-name>Sample App REST API v1.0</display-name>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
+
+    <servlet>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.xran.impl.rest.XranWebApplication</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>
diff --git a/apps/xran/src/test/java/org.onosproject.xran/org/onosproject/xran/impl/DefaultXranStoreTest.java b/apps/xran/src/test/java/org.onosproject.xran/org/onosproject/xran/impl/DefaultXranStoreTest.java
new file mode 100644
index 0000000..3e49869
--- /dev/null
+++ b/apps/xran/src/test/java/org.onosproject.xran/org/onosproject/xran/impl/DefaultXranStoreTest.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+package org.onosproject.xran.impl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.xran.asn1lib.api.CRNTI;
+import org.onosproject.xran.asn1lib.api.ECGI;
+import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier;
+import org.onosproject.xran.asn1lib.api.PLMNIdentity;
+import org.onosproject.xran.asn1lib.util.HexConverter;
+import org.onosproject.xran.impl.entities.RnibCell;
+import org.onosproject.xran.impl.entities.RnibLink;
+import org.onosproject.xran.impl.entities.RnibUe;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.List;
+import java.util.function.Supplier;
+
+import static org.junit.Assert.assertEquals;
+
+public class DefaultXranStoreTest {
+    private static final CRNTI CRNTI0 = new CRNTI(new byte[]{(byte) 0xFF, (byte) 0xFF}, 16);
+    private static final CRNTI CRNTI1 = new CRNTI(new byte[]{(byte) 0xFA, (byte) 0xAF}, 16);
+
+    private static final RnibUe UE0 = new RnibUe();
+    private static final RnibUe UE1 = new RnibUe();
+
+    private static final RnibCell CELL0 = new RnibCell();
+    private static final RnibCell CELL1 = new RnibCell();
+    private static final String ECI0 = "00000010";
+    private static final String ECI1 = "00000020";
+    private static final long UEID0 = 0L;
+    private static final long UEID1 = 1L;
+
+    private static DefaultXranStore store = new DefaultXranStore();
+
+    private static RnibLink primaryLink0;
+    private static RnibLink primaryLink1;
+    private static RnibLink nonServingLink0;
+    private static RnibLink nonServingLink1;
+
+    private Supplier exception = () -> {
+        throw new IllegalArgumentException("item not found");
+    };
+
+    @Before
+    public void setUp() throws Exception {
+        CELL0.setEcgi(hexToEcgi("000001", ECI0));
+        CELL1.setEcgi(hexToEcgi("000002", ECI1));
+
+        UE0.setCrnti(CRNTI0);
+        UE0.setId(UEID0);
+
+        UE1.setCrnti(CRNTI1);
+        UE1.setId(UEID1);
+
+        store.storeCell(CELL0);
+        store.storeCell(CELL1);
+
+        store.storeUe(CELL0, UE0);
+        store.storeUe(CELL1, UE1);
+
+        store.putPrimaryLink(CELL0, UE0);
+        store.putPrimaryLink(CELL1, UE1);
+
+        store.putNonServingLink(CELL0, UEID1);
+        store.putNonServingLink(CELL1, UEID0);
+
+        primaryLink0 = store.getLink(CELL0.getEcgi(), UEID0).orElseThrow(exception);
+        primaryLink1 = store.getLink(CELL1.getEcgi(), UEID1).orElseThrow(exception);
+
+        nonServingLink0 = store.getLink(CELL0.getEcgi(), UEID1).orElseThrow(exception);
+        nonServingLink1 = store.getLink(CELL1.getEcgi(), UEID0).orElseThrow(exception);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        assertEquals("wrong remove", true, store.removeCell(CELL0.getEcgi()));
+        assertEquals("wrong remove", true, store.removeCell(CELL1.getEcgi()));
+
+        assertEquals("wrong remove", true, store.removeUe(UEID0));
+        assertEquals("wrong remove", true, store.removeUe(UEID1));
+
+        assertEquals("wrong remove", true, store.removeLink(primaryLink0.getLinkId()));
+        assertEquals("wrong remove", true, store.removeLink(primaryLink1.getLinkId()));
+
+        assertEquals("wrong remove", true, store.removeLink(nonServingLink0.getLinkId()));
+        assertEquals("wrong remove", true, store.removeLink(nonServingLink1.getLinkId()));
+
+        assertEquals("wrong len", 0, store.getCellNodes().size());
+        assertEquals("wrong len", 0, store.getUeNodes().size());
+        assertEquals("wrong len", 0, store.getNodes().size());
+        assertEquals("wrong len", 0, store.getLinks().size());
+    }
+
+    private ECGI hexToEcgi(String plmnId, String eci) throws Exception {
+        byte[] bytes = HexConverter.fromShortHexString(plmnId);
+        byte[] bytearray = DatatypeConverter.parseHexBinary(eci);
+
+        PLMNIdentity plmnIdentity = new PLMNIdentity(bytes);
+        EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28);
+
+        ECGI ecgi = new ECGI();
+        ecgi.setEUTRANcellIdentifier(eutranCellIdentifier);
+        ecgi.setPLMNIdentity(plmnIdentity);
+
+        return ecgi;
+    }
+
+    @Test
+    public void getPrimaryLink() throws Exception {
+        assertEquals("wrong cell", CELL0, store.getPrimaryCell(UE0).orElseThrow(exception));
+        assertEquals("wrong cell", CELL1, store.getPrimaryCell(UE1).orElseThrow(exception));
+    }
+
+    @Test
+    public void mapSize() throws Exception {
+        assertEquals("wrong len", 2, store.getCellNodes().size());
+        assertEquals("wrong len", 2, store.getUeNodes().size());
+        assertEquals("wrong len", 4, store.getNodes().size());
+        assertEquals("wrong len", 4, store.getLinks().size());
+    }
+
+    @Test
+    public void getUe() throws Exception {
+        // GET FROM ID
+        assertEquals("wrong ue", UE0, store.getUe(UEID0).orElseThrow(exception));
+        assertEquals("wrong ue", UE1, store.getUe(UEID1).orElseThrow(exception));
+
+        // GET FROM ECGI-CRNTI
+        assertEquals("wrong ue", UE0, store.getUe(CELL0.getEcgi(), CRNTI0).orElseThrow(exception));
+        assertEquals("wrong ue", UE1, store.getUe(CELL1.getEcgi(), CRNTI1).orElseThrow(exception));
+
+        // GET FROM CRNTI
+        assertEquals("wrong crnti", CRNTI0, store.getCrnti(UEID0).orElseThrow(exception));
+        assertEquals("wrong crnti", CRNTI1, store.getCrnti(UEID1).orElseThrow(exception));
+    }
+
+    @Test
+    public void getLink() throws Exception {
+        // GET FROM ID
+        assertEquals("wrong link", primaryLink0, store.getLink(CELL0.getEcgi(), UEID0).orElseThrow(exception));
+        assertEquals("wrong link", primaryLink1, store.getLink(CELL1.getEcgi(), UEID1).orElseThrow(exception));
+        assertEquals("wrong link", nonServingLink0, store.getLink(CELL0.getEcgi(), UEID1).orElseThrow(exception));
+        assertEquals("wrong link", nonServingLink1, store.getLink(CELL1.getEcgi(), UEID0).orElseThrow(exception));
+
+        // GET FROM CRNTI
+        assertEquals("wrong link", primaryLink0, store.getLink(CELL0.getEcgi(), CRNTI0).orElseThrow(exception));
+        assertEquals("wrong link", primaryLink1, store.getLink(CELL1.getEcgi(), CRNTI1).orElseThrow(exception));
+        // GET FROM ECIHEX
+        assertEquals("wrong link", primaryLink0, store.getLink(ECI0, UEID0).orElseThrow(exception));
+        assertEquals("wrong link", primaryLink1, store.getLink(ECI1, UEID1).orElseThrow(exception));
+        assertEquals("wrong link", nonServingLink0, store.getLink(ECI0, UEID1).orElseThrow(exception));
+        assertEquals("wrong link", nonServingLink1, store.getLink(ECI1, UEID0).orElseThrow(exception));
+
+        // LINKS SIZE
+        assertEquals("wrong link", 2, store.getLinks(CELL0.getEcgi()).size());
+        assertEquals("wrong link", 2, store.getLinks(ECI0).size());
+        assertEquals("wrong link", 2, store.getLinks(UEID0).size());
+        assertEquals("wrong link", 2, store.getLinks(CELL1.getEcgi()).size());
+        assertEquals("wrong link", 2, store.getLinks(ECI1).size());
+        assertEquals("wrong link", 2, store.getLinks(UEID1).size());
+    }
+
+    @Test
+    public void getNodes() throws Exception {
+        List<RnibCell> cellNodes = store.getCellNodes();
+
+        assertEquals("wrong nodes", true, cellNodes.contains(CELL0));
+        assertEquals("wrong nodes", true, cellNodes.contains(CELL1));
+
+        List<RnibUe> ueNodes = store.getUeNodes();
+
+        assertEquals("wrong nodes", true, ueNodes.contains(UE0));
+        assertEquals("wrong nodes", true, ueNodes.contains(UE1));
+    }
+
+    @Test
+    public void crntiMap() throws Exception {
+        store.getCrnti().forEach(
+                (ecgiCrntiPair, aLong) -> assertEquals("wrong primary",
+                        store.getCell(ecgiCrntiPair.getKey()).get(),
+                        store.getPrimaryCell(store.getUe(aLong).orElseThrow(exception)).get()
+                )
+        );
+    }
+}
\ No newline at end of file
diff --git a/apps/xran/xran-cfg.json b/apps/xran/xran-cfg.json
new file mode 100644
index 0000000..e2f4dec
--- /dev/null
+++ b/apps/xran/xran-cfg.json
@@ -0,0 +1,30 @@
+{
+  "apps": {
+    "org.onosproject.xran": {
+      "xran": {
+        "active_cells": [
+          {
+            "plmn_id": "000001",
+            "eci": "00000010",
+            "ip_addr": "1.1.1.2"
+          },
+          {
+            "plmn_id": "000002",
+            "eci": "00000020",
+            "ip_addr": "1.1.1.3"
+          }
+        ],
+        "l2_meas_report_interval_ms": 5000,
+        "rx_signal_meas_report_interval_ms": 7000,
+        "xranc_cellconfigrequest_interval_seconds": 10,
+        "xranc_bind_ip": "1.1.1.1",
+        "xranc_port": 7891,
+        "admission_success": true,
+        "bearer_success": true,
+        "no_meas_link_removal_ms": 1000000,
+        "idle_ue_removal_ms": 1,
+        "nb_response_timeout_ms": 10000
+      }
+    }
+  }
+}
