diff --git a/.gitignore b/.gitignore
index db47387c8c8ff9900a59107642221960134aa1f1..e0f9e5485d5425ab6fd4e1f45420364c64a93f82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,7 +34,7 @@ MANIFEST
 *.manifest
 .manifest/
 *.spec
-
+scripts/aa
 # Installer logs
 pip-log.txt
 pip-delete-this-directory.txt
diff --git a/my_deploy.sh b/my_deploy.sh
index 57d92e9cb3a1de0049609b27d6be5bc9e25af88d..358e820d680b6bedff94848998613108ff724b03 100755
--- a/my_deploy.sh
+++ b/my_deploy.sh
@@ -20,7 +20,7 @@
 export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/"
 
 # Set the list of components, separated by spaces, you want to build images for, and deploy.
-export TFS_COMPONENTS="context device pathcomp opticalcontroller service slice  webui nbi"
+export TFS_COMPONENTS="context device pathcomp opticalcontroller service webui nbi"
 
 # Uncomment to activate Monitoring (old)
 #export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring"
diff --git a/src/context/service/database/Link.py b/src/context/service/database/Link.py
index 1b8c6d06aac588f3e9744416d3948e8661dbc556..c71f1fc8fcf0589e69d204f2f5de282e0c213a28 100644
--- a/src/context/service/database/Link.py
+++ b/src/context/service/database/Link.py
@@ -18,7 +18,9 @@ from sqlalchemy.engine import Engine
 from sqlalchemy.orm import Session, selectinload, sessionmaker
 from sqlalchemy_cockroachdb import run_transaction
 from typing import Dict, List, Optional, Set, Tuple
-from common.proto.context_pb2 import Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId
+from common.proto.context_pb2 import (
+    Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId
+)
 from common.message_broker.MessageBroker import MessageBroker
 from common.method_wrappers.ServiceExceptions import NotFoundException
 from common.tools.object_factory.Link import json_link_id
diff --git a/src/context/service/database/OpticalLink.py b/src/context/service/database/OpticalLink.py
index 53fd7bdb5a5964376c6ffb94c6b130b6744f7215..e371d374a64582ccc26dbc5f666f29ee65ce56b5 100644
--- a/src/context/service/database/OpticalLink.py
+++ b/src/context/service/database/OpticalLink.py
@@ -66,9 +66,10 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request
 
     now = datetime.datetime.utcnow()
 
-    # By default, always add link to default Context/Topology
     topology_uuids : Set[str] = set()
     related_topologies : List[Dict] = list()
+    
+    # By default, always add link to default Context/Topology
     _,topology_uuid = topology_get_uuid(TopologyId(), allow_random=False, allow_default=True)
     related_topologies.append({
         'topology_uuid': topology_uuid,
@@ -77,15 +78,14 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request
     topology_uuids.add(topology_uuid)
 
     link_endpoints_data : List[Dict] = list()
-
     for i,endpoint_id in enumerate(request.link_endpoint_ids):
-        endpoint_topology_uuid, endpoint_device_uuid, endpoint_uuid = endpoint_get_uuid(
-              endpoint_id, endpoint_name="", allow_random=True)
+        endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid(
+            endpoint_id, allow_random=False)
 
         link_endpoints_data.append({
             'link_uuid'    : link_uuid,
             'endpoint_uuid': endpoint_uuid,
-           
+            'position'     : i,
         })
 
         if endpoint_topology_uuid not in topology_uuids:
diff --git a/src/context/service/database/models/OpticalLinkModel.py b/src/context/service/database/models/OpticalLinkModel.py
index 930e8935c5af48793915c72df451ec48dc782a04..4c218fd9d66d06ad4a6772b8a5ee791e6b52294e 100644
--- a/src/context/service/database/models/OpticalLinkModel.py
+++ b/src/context/service/database/models/OpticalLinkModel.py
@@ -12,13 +12,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
-from sqlalchemy import Column, DateTime, ForeignKey, Integer, String ,Boolean
+import operator
+from sqlalchemy import (
+    Boolean, CheckConstraint, Column, DateTime, ForeignKey, Integer, String
+)
 from sqlalchemy.dialects.postgresql import UUID
 from sqlalchemy.orm import relationship
 from typing import Dict
 from ._Base import _Base
-from .Slot import C_Slot ,S_Slot , L_Slot
+from .Slot import C_Slot, S_Slot, L_Slot
 
 class OpticalLinkModel(_Base):
     __tablename__ = 'opticallink'
@@ -59,7 +61,7 @@ class OpticalLinkModel(_Base):
             },
             'link_endpoint_ids' : [
                 optical_endpoint.endpoint.dump_id()
-                for optical_endpoint in self.opticallink_endpoints
+                for optical_endpoint in sorted(self.opticallink_endpoints, key=operator.attrgetter('position'))
             ],
         }
         return result
@@ -69,6 +71,11 @@ class OpticalLinkEndPointModel(_Base):
 
     link_uuid     = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True)
     endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid',       ondelete='RESTRICT'), primary_key=True, index=True)
-
+    position      = Column(Integer, nullable=False)
+    
     optical_link  = relationship('OpticalLinkModel', back_populates='opticallink_endpoints')
     endpoint      = relationship('EndPointModel',    lazy='selectin')
+
+    __table_args__ = (
+        CheckConstraint(position >= 0, name='check_position_value'),
+    )
\ No newline at end of file
diff --git a/src/device/Dockerfile b/src/device/Dockerfile
index 2da34c9eccdcf5c353c63d691ee549a61aec8d62..701034f18cf1eb393b5ea57209c145e03240e764 100644
--- a/src/device/Dockerfile
+++ b/src/device/Dockerfile
@@ -23,11 +23,11 @@ RUN apt-get --yes --quiet --quiet update && \
 # - Ref: https://github.com/CESNET/libyang
 # - Ref: https://github.com/CESNET/libyang-python/
 RUN mkdir -p /var/libyang
-#RUN git clone https://github.com/CESNET/libyang.git /var/libyang
-COPY libyang/. /var/libyang
+RUN git clone https://github.com/CESNET/libyang.git /var/libyang
+#COPY /var/libyang/. /var/libyang
 WORKDIR /var/libyang
 RUN git fetch
-#RUN git checkout v2.1.148
+RUN git checkout v2.1.148
 RUN mkdir -p /var/libyang/build
 WORKDIR /var/libyang/build
 RUN cmake -D CMAKE_BUILD_TYPE:String="Release" ..
diff --git a/src/nbi/Dockerfile b/src/nbi/Dockerfile
index eaa3b9d5b113b80d0b45260c437905984b470249..e9b4fd4cc8b8472edf2eee1d44e2f17a279ce0c2 100644
--- a/src/nbi/Dockerfile
+++ b/src/nbi/Dockerfile
@@ -23,11 +23,11 @@ RUN apt-get --yes --quiet --quiet update && \
 # - Ref: https://github.com/CESNET/libyang
 # - Ref: https://github.com/CESNET/libyang-python/
 RUN mkdir -p /var/libyang
-#RUN git clone https://github.com/CESNET/libyang.git /var/libyang
-COPY libyang/. /var/libyang
+RUN git clone https://github.com/CESNET/libyang.git /var/libyang
+#COPY libyang/. /var/libyang
 WORKDIR /var/libyang
 RUN git fetch
-#RUN git checkout v2.1.148
+RUN git checkout v2.1.148
 RUN mkdir -p /var/libyang/build
 WORKDIR /var/libyang/build
 RUN cmake -D CMAKE_BUILD_TYPE:String="Release" ..
diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py
index 0b711aa7d11c05118ac6d5cc5c48fc73c93a1295..075de5956f980ce602ae8a6f7ad600474e1cf3c4 100644
--- a/src/opticalcontroller/OpticalController.py
+++ b/src/opticalcontroller/OpticalController.py
@@ -12,13 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging, time
 from flask import Flask
 from flask import render_template
+from common.DeviceTypes import DeviceTypeEnum
 from flask_restplus import Resource, Api
 from opticalcontroller.tools import *
 from opticalcontroller.variables import *
 from opticalcontroller.RSA import RSA
-import time , logging
 from common.proto.context_pb2 import TopologyId , OpticalLink
 import json
 from google.protobuf.message import Message
@@ -366,56 +367,71 @@ class GetTopology(Resource):
         topog_id.context_id.context_uuid.uuid=context_id
         
         try: 
-                links_dict={"optical_links":[]}
-                node_dict = {}
-                topo , nodes = readTopologyDataFromContext(topog_id)
+            links_dict={"optical_links":[]}
+            node_dict = {}
+            topo , nodes = readTopologyDataFromContext(topog_id)
+
+            OPTICAL_ROADM_TYPES = {
+                DeviceTypeEnum.OPTICAL_ROADM.value, DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value
+            }
+            OPTICAL_TRANSPONDER_TYPES = {
+                DeviceTypeEnum.OPTICAL_TRANSPONDER.value, DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value
+            }
+            added_device_uuids = set()
+            for device in nodes:
+                if device.device_type in OPTICAL_ROADM_TYPES:
+                    dev_type = "OC-ROADM"
+                elif device.device_type in OPTICAL_TRANSPONDER_TYPES:
+                    dev_type = "OC-TP"
+                else:
+                    continue
+
+                dev_dic = {
+                    "id":device.device_id.device_uuid.uuid,
+                    #"ip":f"10.30.2.{207+i}",
+                    #"port":"50001",
+                    "type": dev_type,
+                    "driver": "OpticalOC"
+                }
+                node_dict[device.name] = dev_dic
+                added_device_uuids.add(device.device_id.device_uuid.uuid)
+                #i+=1
+                #print(f"refresh_optical controller optical_links_dict= {links_dict}")
+                #print(f"refresh_optical controller node_dict  {node_dict}")
+            
+            for link in topo:
+                endpoint_id_a = link.link_endpoint_ids[ 0]
+                endpoint_id_z = link.link_endpoint_ids[-1]
 
-                for link in topo: 
-                      link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
-                      
-                      if "c_slots" in link_dict_type["optical_details"] : 
-                          link_dict_type["optical_details"]["c_slots"]=order_dict(link_dict_type["optical_details"]["c_slots"])
-                          
-                      if "l_slots" in link_dict_type["optical_details"] : 
-                          link_dict_type["optical_details"]["l_slots"]=order_dict(link_dict_type["optical_details"]["l_slots"])
-                          
-                      if "s_slots" in link_dict_type["optical_details"] : 
-                          link_dict_type["optical_details"]["s_slots"]=order_dict(link_dict_type["optical_details"]["s_slots"])
-                          
-                      links_dict["optical_links"].append(link_dict_type)
+                device_uuid_a = endpoint_id_a.device_id.device_uuid.uuid
+                if device_uuid_a not in added_device_uuids: continue
+
+                device_uuid_z = endpoint_id_z.device_id.device_uuid.uuid
+                if device_uuid_z not in added_device_uuids: continue
+
+                link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
+                
+                if "c_slots" in link_dict_type["optical_details"] : 
+                    link_dict_type["optical_details"]["c_slots"]=order_dict(link_dict_type["optical_details"]["c_slots"])
                     
+                if "l_slots" in link_dict_type["optical_details"] : 
+                    link_dict_type["optical_details"]["l_slots"]=order_dict(link_dict_type["optical_details"]["l_slots"])
                     
-                
-                for device in nodes :
-                    dev_dic = {}
-                    dev_dic = {
-                            "id":device.device_id.device_uuid.uuid,
-                            #"ip":f"10.30.2.{207+i}",
-                            #"port":"50001",
-                            "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-TP",
-                            "driver": "OpticalOC"
-                        }
-                    node_dict[device.name]=dev_dic
-                    #i+=1
-                    #print(f"refresh_optical controller optical_links_dict= {links_dict}")    
-                    #print(f"refresh_optical controller node_dict  {node_dict}") 
-      
-                rsa = RSA(node_dict, links_dict)
-                if debug:
-                    print(f'rsa.init_link_slots2() {rsa}')
-                    print(rsa.init_link_slots2())
-            
-            
-                return  "ok" ,200
+                if "s_slots" in link_dict_type["optical_details"] : 
+                    link_dict_type["optical_details"]["s_slots"]=order_dict(link_dict_type["optical_details"]["s_slots"])
+                    
+                links_dict["optical_links"].append(link_dict_type)
+    
+            rsa = RSA(node_dict, links_dict)
+            if debug:
+                print(f'rsa.init_link_slots2() {rsa}')
+                print(rsa.init_link_slots2())
+        
+        
+            return  "ok" ,200
         except Exception as e:
             print(f"err {e}")
             return "Error", 400
-        
-
-
-    
-if __name__ == '__main__':
-    
-
     
-    app.run(host='0.0.0.0', port=10060)
+if __name__ == '__main__': 
+    app.run(host='0.0.0.0', port=10060, debug=True)
\ No newline at end of file
diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py
index 2395f594851dd61de4cbf43e3fc0b2fbbb73563f..39b5772dff1f78c6bfa40ed540af8e56927b5c1c 100644
--- a/src/opticalcontroller/RSA.py
+++ b/src/opticalcontroller/RSA.py
@@ -12,10 +12,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging
 from opticalcontroller.dijkstra import *
 from opticalcontroller.tools import *
 from opticalcontroller.variables import *
 
+LOGGER = logging.getLogger(__name__)
+
+def print(*args) -> None:
+    LOGGER.info(' '.join([str(a) for a in args]))
 
 class RSA():
     def __init__(self, nodes, links):