Showing
1 changed file
with
32 additions
and
14 deletions
| ... | @@ -28,6 +28,7 @@ | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | ||
| 29 | // configuration data | 29 | // configuration data |
| 30 | var config = { | 30 | var config = { |
| 31 | + useLiveData: true, | ||
| 31 | debugOn: false, | 32 | debugOn: false, |
| 32 | debug: { | 33 | debug: { |
| 33 | showNodeXY: false, | 34 | showNodeXY: false, |
| ... | @@ -37,10 +38,18 @@ | ... | @@ -37,10 +38,18 @@ |
| 37 | layering: true, | 38 | layering: true, |
| 38 | collisionPrevention: true | 39 | collisionPrevention: true |
| 39 | }, | 40 | }, |
| 41 | + data: { | ||
| 42 | + live: { | ||
| 40 | jsonUrl: 'rs/topology/graph', | 43 | jsonUrl: 'rs/topology/graph', |
| 41 | - jsonPrefix: '', | 44 | + detailPrefix: 'rs/topology/graph/', |
| 42 | - XjsonUrl: 'json/network.json', | 45 | + detailSuffix: '' |
| 43 | - XjsonPrefix: 'json/', | 46 | + }, |
| 47 | + fake: { | ||
| 48 | + jsonUrl: 'json/network2.json', | ||
| 49 | + detailPrefix: 'json/', | ||
| 50 | + detailSuffix: '.json' | ||
| 51 | + } | ||
| 52 | + }, | ||
| 44 | iconUrl: { | 53 | iconUrl: { |
| 45 | device: 'img/device.png', | 54 | device: 'img/device.png', |
| 46 | host: 'img/host.png', | 55 | host: 'img/host.png', |
| ... | @@ -109,6 +118,22 @@ | ... | @@ -109,6 +118,22 @@ |
| 109 | return config.debugOn && config.debug[what]; | 118 | return config.debugOn && config.debug[what]; |
| 110 | } | 119 | } |
| 111 | 120 | ||
| 121 | + function urlData() { | ||
| 122 | + return config.data[config.useLiveData ? 'live' : 'fake']; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + function networkJsonUrl() { | ||
| 126 | + return urlData().jsonUrl; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + function detailJsonUrl(id) { | ||
| 130 | + var u = urlData(), | ||
| 131 | + encId = config.useLiveData ? encodeURIComponent(id) | ||
| 132 | + : id.replace(/[^a-z0-9]/gi, '_'); | ||
| 133 | + return u.detailPrefix + encId + u.detailSuffix; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + | ||
| 112 | // load the topology view of the network | 137 | // load the topology view of the network |
| 113 | function loadNetworkView() { | 138 | function loadNetworkView() { |
| 114 | // Hey, here I am, calling something on the ONOS api: | 139 | // Hey, here I am, calling something on the ONOS api: |
| ... | @@ -117,10 +142,11 @@ | ... | @@ -117,10 +142,11 @@ |
| 117 | resize(); | 142 | resize(); |
| 118 | 143 | ||
| 119 | // go get our network data from the server... | 144 | // go get our network data from the server... |
| 120 | - d3.json(config.jsonUrl, function (err, data) { | 145 | + var url = networkJsonUrl(); |
| 146 | + d3.json(url , function (err, data) { | ||
| 121 | if (err) { | 147 | if (err) { |
| 122 | alert('Oops! Error reading JSON...\n\n' + | 148 | alert('Oops! Error reading JSON...\n\n' + |
| 123 | - 'URL: ' + config.jsonUrl + '\n\n' + | 149 | + 'URL: ' + url + '\n\n' + |
| 124 | 'Error: ' + err.message); | 150 | 'Error: ' + err.message); |
| 125 | return; | 151 | return; |
| 126 | } | 152 | } |
| ... | @@ -898,21 +924,13 @@ | ... | @@ -898,21 +924,13 @@ |
| 898 | flyinPane(null); | 924 | flyinPane(null); |
| 899 | } | 925 | } |
| 900 | 926 | ||
| 901 | - function detailUrl(id) { | ||
| 902 | - if (config.jsonPrefix) { | ||
| 903 | - var safeId = id.replace(/[^a-z0-9]/gi, '_'); | ||
| 904 | - return config.jsonPrefix + safeId + '.json'; | ||
| 905 | - } | ||
| 906 | - return config.jsonUrl + '/' + encodeURIComponent(id); | ||
| 907 | - } | ||
| 908 | - | ||
| 909 | function flyinPane(obj) { | 927 | function flyinPane(obj) { |
| 910 | var pane = d3.select('#flyout'), | 928 | var pane = d3.select('#flyout'), |
| 911 | url; | 929 | url; |
| 912 | 930 | ||
| 913 | if (obj) { | 931 | if (obj) { |
| 914 | // go get details of the selected object from the server... | 932 | // go get details of the selected object from the server... |
| 915 | - url = detailUrl(obj.id); | 933 | + url = detailJsonUrl(obj.id); |
| 916 | d3.json(url, function (err, data) { | 934 | d3.json(url, function (err, data) { |
| 917 | if (err) { | 935 | if (err) { |
| 918 | alert('Oops! Error reading JSON...\n\n' + | 936 | alert('Oops! Error reading JSON...\n\n' + | ... | ... |
-
Please register or login to post a comment