Added subscriber public IP and higlightig only used vSG instance
diff --git a/views/ngXosViews/diagnostic/mocks/data/tenants.json b/views/ngXosViews/diagnostic/mocks/data/tenants.json
index d6288a5..77bea93 100644
--- a/views/ngXosViews/diagnostic/mocks/data/tenants.json
+++ b/views/ngXosViews/diagnostic/mocks/data/tenants.json
@@ -61,7 +61,7 @@
         "kind": "vCPE", 
         "provider_service": 2, 
         "subscriber_service": null, 
-        "subscriber_tenant": "3", 
+        "subscriber_tenant": 3, 
         "subscriber_user": null, 
         "subscriber_root": null, 
         "service_specific_id": null, 
@@ -108,7 +108,7 @@
         "kind": "vBNG", 
         "provider_service": 1, 
         "subscriber_service": null, 
-        "subscriber_tenant": "4", 
+        "subscriber_tenant": 4, 
         "subscriber_user": null, 
         "subscriber_root": null, 
         "service_specific_id": null, 
@@ -200,7 +200,7 @@
         "kind": "vCPE", 
         "provider_service": 2, 
         "subscriber_service": null, 
-        "subscriber_tenant": "3", 
+        "subscriber_tenant": 3, 
         "subscriber_user": null, 
         "subscriber_root": null, 
         "service_specific_id": null, 
diff --git a/views/ngXosViews/diagnostic/spec/serviceChain.test.js b/views/ngXosViews/diagnostic/spec/serviceChain.test.js
index 14255e2..0c06ea8 100644
--- a/views/ngXosViews/diagnostic/spec/serviceChain.test.js
+++ b/views/ngXosViews/diagnostic/spec/serviceChain.test.js
@@ -94,7 +94,7 @@
       }
     ];
 
-    const relations = [
+    const tenants = [
       {
         provider_service: 2,
         subscriber_service: 1,
@@ -113,8 +113,8 @@
       }
     ];
 
-    it('should return a tree ordered by relations', () => {
-      let tree = Service.buildSubscriberServiceTree(services, relations);
+    it('should return a tree ordered by tenants', () => {
+      let tree = Service.buildSubscriberServiceTree(services, tenants);
 
       expect(tree.name).toBe('fakeSubs');
       expect(tree.parent).toBeNull();
@@ -122,10 +122,13 @@
 
       expect(tree.children[0].name).toBe('service-1');
       expect(tree.children[0].parent).toBeNull();
+      expect(tree.children[0].tenant).toEqual({subscriber_root: 1, provider_service: 1});
       expect(tree.children[0].children.length).toBe(2);
 
       expect(tree.children[0].children[0].name).toBe('service-2');
+      expect(tree.children[0].children[0].tenant).toEqual({subscriber_service: 1, provider_service: 2});;
       expect(tree.children[0].children[0].children[0].name).toBe('service-3');
+
       expect(tree.children[0].children[0].children[0].children[0].name).toBe('Router');
 
       expect(tree.children[0].children[1].name).toBe('service-4');
diff --git a/views/ngXosViews/diagnostic/src/index.html b/views/ngXosViews/diagnostic/src/index.html
index 34deef6..5678816 100644
--- a/views/ngXosViews/diagnostic/src/index.html
+++ b/views/ngXosViews/diagnostic/src/index.html
@@ -33,7 +33,6 @@
 <script src="/api/ng-xos.js"></script>
 <script src="/api/ng-hpcapi.js"></script>
 <script src="/.tmp/main.js"></script>
-<script src="/.tmp/subscriber_service.js"></script>
 <script src="/.tmp/subscriber-modal.js"></script>
 <script src="/.tmp/serviceTopologyHelper.js"></script>
 <script src="/.tmp/serviceTopology.js"></script>
@@ -45,4 +44,5 @@
 <script src="/.tmp/diagnostic.js"></script>
 <script src="/.tmp/d3.js"></script>
 <script src="/.tmp/config.js"></script>
+<script src="/.tmp/chart_data_service.js"></script>
 <!-- endinject -->
diff --git a/views/ngXosViews/diagnostic/src/js/chart_data_service.js b/views/ngXosViews/diagnostic/src/js/chart_data_service.js
new file mode 100644
index 0000000..4c53a03
--- /dev/null
+++ b/views/ngXosViews/diagnostic/src/js/chart_data_service.js
@@ -0,0 +1,157 @@
+(function () {
+  'use strict';
+
+  angular.module('xos.serviceTopology')
+  .service('ChartData', function($rootScope, $q, lodash, Tenant, Node, serviceTopologyConfig, Ceilometer) {
+    this.currentSubscriber = null;
+    this.currentServiceChain = null;
+
+    this.logicTopologyData = {
+      name: 'Router',
+      type: 'router',
+      children: [
+        {
+          name: 'WAN',
+          type: 'network',
+          children: [
+            {
+              name: 'Rack',
+              type: 'rack',
+              computeNodes: [],
+              children: [
+                {
+                  name: 'LAN',
+                  type: 'network',
+                  children: [{
+                    name: 'Subscriber',
+                    type: 'subscriber'
+                  }] //subscribers goes here
+                }
+              ]
+            }
+          ]
+        }
+      ]
+    };
+
+    this.getLogicTree = () => {
+      const deferred = $q.defer();
+
+      Node.queryWithInstances().$promise
+        .then((computeNodes) => {
+          this.logicTopologyData.children[0].children[0].computeNodes = computeNodes;
+          // LogicTopologyHelper.updateTree(svg);
+          deferred.resolve(this.logicTopologyData);
+        });
+
+      return deferred.promise;
+    };
+
+    /**
+    * Add Subscriber tag to LAN Network
+    */
+    this.addSubscriberTag = (tags) => {
+      this.logicTopologyData.children[0].children[0].children[0].subscriberTag = {
+        cTag: tags.c_tag,
+        sTag: tags.s_tag
+      }
+    };
+
+    /**
+    * Add Subscribers to the tree
+    */
+    this.addSubscriber = (subscriber) => {
+      subscriber.children = subscriber.devices;
+
+      // add subscriber to data tree
+      this.logicTopologyData.children[0].children[0].children[0].children = [subscriber];
+      return this.logicTopologyData;
+    };
+
+    this.getSubscriberTag = () => {
+
+      this.addSubscriberTag(JSON.parse(this.currentServiceChain.children[0].tenant.service_specific_attribute));
+
+    };
+
+    this.getSubscriberIP = () => {
+      const ip = this.currentServiceChain.children[0].children[0].tenant.wan_container_ip;
+      this.logicTopologyData.children[0].subscriberIP = ip;
+    };
+
+    this.selectSubscriber = (subscriber) => {
+
+      // append the device with to config settings
+      serviceTopologyConfig.elWidths.push(160);
+
+      this.addSubscriber(angular.copy(subscriber));
+
+      this.getSubscriberTag();
+      this.getSubscriberIP();
+
+    };
+
+    this.highlightInstances = (instances) => {
+
+      const computeNodes = this.logicTopologyData.children[0].children[0].computeNodes;
+
+      // unselect all
+      computeNodes.map((node) => {
+        node.instances.map((instance) => {
+          instance.selected = false
+          return instance;
+        });
+      });
+
+      lodash.forEach(instances, (instance) => {
+        computeNodes.map((node) => {
+          node.instances.map((d3instance) => {
+            if(d3instance.id === instance.id){
+              d3instance.selected = true;
+            }
+            return d3instance;
+          });
+        });
+      });
+
+    }
+
+    this.getInstanceStatus = (service) => {
+      const deferred = $q.defer();
+
+      // NOTE consider if subscriber is selected or not,
+      // if not select instances
+      // else select containers (and follow subscriber chain to find the correct instance)
+
+      let p;
+
+      if(this.currentSubscriber){
+        let instances = [JSON.parse(service.tenant.service_specific_attribute).instance_id];
+        p = Ceilometer.getInstancesStats(instances);
+      }
+      else {
+        let param = {
+          'service_vsg': {kind: 'vCPE'},
+          'service_vbng': {kind: 'vBNG'},
+          'service_volt': {kind: 'vOLT'}
+        };
+
+        p = Tenant.queryVsgInstances(param[service.name]).$promise
+        .then((instances) => {
+
+          return Ceilometer.getInstancesStats(instances);
+        });
+      }
+
+      p.then((instances) => {
+        this.highlightInstances(instances);
+        deferred.resolve(instances);
+      })
+      .catch((e) => {
+        deferred.reject(e);
+      });
+
+      return deferred.promise;
+    };
+  })
+})();
diff --git a/views/ngXosViews/diagnostic/src/js/diagnostic.js b/views/ngXosViews/diagnostic/src/js/diagnostic.js
index d65194c..f3c133a 100644
--- a/views/ngXosViews/diagnostic/src/js/diagnostic.js
+++ b/views/ngXosViews/diagnostic/src/js/diagnostic.js
@@ -7,7 +7,7 @@
       restrict: 'E',
       templateUrl: 'templates/diagnostic.tpl.html',
       controllerAs: 'vm',
-      controller: function(Subscribers, ServiceRelation, $rootScope){
+      controller: function(ChartData, Subscribers, ServiceRelation, $rootScope){
         this.loader = true;
         this.error = false;
         Subscribers.query().$promise
@@ -30,10 +30,12 @@
           ServiceRelation.getBySubscriber(subscriber)
           .then((serviceChain) => {
             this.serviceChain = serviceChain;
+            ChartData.currentServiceChain = serviceChain;
             return Subscribers.getWithDevices({id: subscriber.id}).$promise;
           })
           .then((subscriber) => {
             this.selectedSubscriber = subscriber;
+            ChartData.currentSubscriber = subscriber;
           });
         });
       }
diff --git a/views/ngXosViews/diagnostic/src/js/logicTopology.js b/views/ngXosViews/diagnostic/src/js/logicTopology.js
index 5ca0b30..8e7e741 100644
--- a/views/ngXosViews/diagnostic/src/js/logicTopology.js
+++ b/views/ngXosViews/diagnostic/src/js/logicTopology.js
@@ -11,7 +11,7 @@
       bindToController: true,
       controllerAs: 'vm',
       templateUrl: 'templates/logicTopology.tpl.html',
-      controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig){
+      controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData){
         $log.info('Logic Plane');
 
         var svg;
@@ -26,32 +26,15 @@
           .style('height', `${el.clientHeight}px`);
         }
 
-        $scope.$watch(() => this.subscribers, (subscribers) => {
-          if(subscribers){
-
-            Node.queryWithInstances().$promise
-            .then((computeNodes) => {
-              LogicTopologyHelper.addComputeNodes(computeNodes);
-              LogicTopologyHelper.updateTree(svg);
-            });
-            
-          }
+        ChartData.getLogicTree()
+        .then((tree) => {
+          LogicTopologyHelper.updateTree(svg);
         });
 
         $scope.$watch(() => this.selected, (selected) => {
           if(selected){
-            $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`);
-            
-            // append the device with to config settings
-            serviceTopologyConfig.elWidths.push(160);
-
-            LogicTopologyHelper.addSubscriber(angular.copy(selected));
-
-            Tenant.getSubscriberTag({subscriber_root: selected.id}).$promise
-            .then((tags) => {
-              LogicTopologyHelper.addSubscriberTag(tags);
-              LogicTopologyHelper.updateTree(svg);
-            })
+            ChartData.selectSubscriber(selected);
+            LogicTopologyHelper.updateTree(svg);
           }
         });
 
@@ -59,30 +42,14 @@
           this.hideInstanceStats = true;
           $timeout(() => {
             this.selectedInstances = [];
-            LogicTopologyHelper.getInstanceStatus([]);
+            ChartData.highlightInstances([]);
             LogicTopologyHelper.updateTree(svg);
           }, 500);
         });
 
         $rootScope.$on('instance.detail', (evt, service) => {
-
-          // NOTE consider if subscriber is selected or not,
-          // if not select instances
-          // else select containers (and follow subscriber chain to find the correct instance)
-
-          let param = {
-            'service_vsg': {kind: 'vCPE'},
-            'service_vbng': {kind: 'vBNG'},
-            'service_volt': {kind: 'vOLT'}
-          };
-
-          Tenant.queryVsgInstances(param[service.name]).$promise
+          ChartData.getInstanceStatus(service)
           .then((instances) => {
-
-            return Ceilometer.getInstancesStats(instances);
-          })
-          .then((instances) => {
-            console.log(instances);
             this.hideInstanceStats = false;
             // HACK if array is empty wait for animation
             if(instances.length === 0){
@@ -94,13 +61,8 @@
             else{
               this.selectedInstances = instances;
             }
-            
-            LogicTopologyHelper.getInstanceStatus(instances);
             LogicTopologyHelper.updateTree(svg);
           })
-          .catch((e) => {
-            throw new Error(e);
-          });
         })
 
         handleSvg($element[0]);
diff --git a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
index f17b103..b0184ef 100644
--- a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
@@ -2,37 +2,11 @@
   'use strict';
 
   angular.module('xos.serviceTopology')
-  .service('LogicTopologyHelper', function($window, $log, $rootScope, lodash, serviceTopologyConfig, NodeDrawer){
+  .service('LogicTopologyHelper', function($window, $log, $rootScope, lodash, serviceTopologyConfig, NodeDrawer, ChartData){
 
     var diagonal, nodes, links, i = 0, svgWidth, svgHeight, layout;
 
-    const baseData = {
-      name: 'Router',
-      type: 'router',
-      children: [
-        {
-          name: 'WAN',
-          type: 'network',
-          children: [
-            {
-              name: 'Rack',
-              type: 'rack',
-              computeNodes: [],
-              children: [
-                {
-                  name: 'LAN',
-                  type: 'network',
-                  children: [{
-                    name: 'Subscriber',
-                    type: 'subscriber'
-                  }] //subscribers goes here
-                }
-              ]
-            }
-          ]
-        }
-      ]
-    };
+    const baseData = ChartData.logicTopologyData;
 
     /**
      * Calculate the horizontal position for each element.
@@ -198,62 +172,6 @@
       drawLinks(svg, links);
     }
 
-    /**
-    * Add Subscribers to the tree
-    */
-    this.addSubscriber = (subscriber) => {
-
-
-      subscriber.children = subscriber.devices;
-
-      // add subscriber to data tree
-      baseData.children[0].children[0].children[0].children = [subscriber];
-      return baseData;
-    };
-
-    /**
-    * Add Subscriber tag to LAN Network
-    */
-   
-    this.addSubscriberTag = (tags) => {
-      baseData.children[0].children[0].children[0].subscriberTag = {
-        cTag: tags.c_tag,
-        sTag: tags.s_tag
-      }
-    };
-
-    /**
-    * Add compute nodes to the rack element
-    */
-   
-    this.addComputeNodes = (computeNodes) => {
-      baseData.children[0].children[0].computeNodes = computeNodes;
-    };
-
-    this.getInstanceStatus = (instances) => {
-
-      const computeNodes = baseData.children[0].children[0].computeNodes;
-
-      // unselect all
-      computeNodes.map((node) => {
-        node.instances.map((instance) => {
-          instance.selected = false
-          return instance;
-        });
-      });
-
-      lodash.forEach(instances, (instance) => {
-        computeNodes.map((node) => {
-          node.instances.map((d3instance) => {
-            if(d3instance.id === instance.id){
-              d3instance.selected = true;
-            }
-            return d3instance;
-          });
-        });
-      });
-
-    }
   });
 
 }());
\ No newline at end of file
diff --git a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
index 94ff406..7c76e61 100644
--- a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
+++ b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
@@ -45,6 +45,15 @@
           })
           .text(() => `S-Tag: ${n.subscriberTag.sTag}`);
         }
+
+        if(n.name === 'WAN' && angular.isDefined(n.subscriberIP)){
+          currentNode.append('text')
+          .attr({
+            'text-anchor': 'middle',
+            y: 40
+          })
+          .text(() => `Public IP: ${n.subscriberIP}`);
+        }
       });
     }
 
diff --git a/views/ngXosViews/diagnostic/src/js/rest_services.js b/views/ngXosViews/diagnostic/src/js/rest_services.js
index 877b485..522a126 100644
--- a/views/ngXosViews/diagnostic/src/js/rest_services.js
+++ b/views/ngXosViews/diagnostic/src/js/rest_services.js
@@ -192,7 +192,6 @@
               devices.map(d => d.type = 'device');
               res.data.devices = devices;
               res.data.type = 'subscriber';
-              console.log(res.data);
               d.resolve(res.data);
             })
             .catch(err => {
@@ -257,7 +256,7 @@
       return levelServices;
     };
 
-    const buildLevel = (tenants, services, rootService, parentName = null) => {
+    const buildLevel = (tenants, services, rootService, rootTenant, parentName = null) => {
 
       // build an array of unlinked services
       // these are the services that should still placed in the tree
@@ -279,11 +278,13 @@
         parent: parentName,
         type: 'service',
         service: rootService,
+        tenant: rootTenant,
         children: []
       };
 
       lodash.forEach(levelServices, (service) => {
-        tree.children.push(buildLevel(tenants, unlinkedServices, service, rootService.humanReadableName));
+        let tenant = lodash.find(tenants, {subscriber_tenant: rootTenant.id, provider_service: service.id});
+        tree.children.push(buildLevel(tenants, unlinkedServices, service, tenant, rootService.humanReadableName));
       });
 
       // if it is the last element append internet
@@ -303,10 +304,10 @@
       // find the root service
       // it is the one attached to subsriber_root
       // as now we have only one root so this can work
-      const rootServiceId = lodash.find(tenants, {subscriber_root: subscriber.id}).provider_service;
-      const rootService = lodash.find(services, {id: rootServiceId});
+      const rootTenant = lodash.find(tenants, {subscriber_root: subscriber.id});
+      const rootService = lodash.find(services, {id: rootTenant.provider_service});
 
-      const serviceTree = buildLevel(tenants, services, rootService);
+      const serviceTree = buildLevel(tenants, services, rootService, rootTenant);
 
       return {
         name: subscriber.name,
diff --git a/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js b/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
index 47fc5eb..7ca925b 100644
--- a/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
@@ -226,7 +226,7 @@
         return updateTree(_svg, _layout, _source);
       }
       
-      $rootScope.$emit('instance.detail', {name: d.name});
+      $rootScope.$emit('instance.detail', {name: d.name, service: d.service, tenant: d.tenant});
 
       // unselect all
       _svg.selectAll('circle')