blob: c5d8f9bff2cc9bbf13a7ee615faca1f173f23457 [file] [log] [blame]
Pankaj Berdec4ae4b82013-01-12 09:56:47 -08001/*
2 Copyright 2012 IBM
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17window.Topology = Backbone.Model.extend({
18
19 url:"/wm/topology/links/json",
20
21 defaults:{
22 nodes: [],
23 links: [],
24 },
25
26 initialize:function () {
27 var self = this;
28 console.log("fetching topology")
29 $.ajax({
30 url:hackBase + self.url,
31 dataType:"json",
32 success:function (data) {
33 console.log("fetched topology: " + data.length);
34 // console.log(data);
35 self.nodes = {};
36 self.links = [];
37
38 // step 1: build unique array of switch IDs
39 /* this doesn't work if there's only one switch,
40 because there are no switch-switch links
41 _.each(data, function (l) {
42 self.nodes[l['src-switch']] = true;
43 self.nodes[l['dst-switch']] = true;
44 });
45 // console.log(self.nodes);
46 var nl = _.keys(self.nodes);
47 */
48 var nl = swl.pluck('id');
49 self.nodes = _.map(nl, function (n) {return {name:n}});
50
51 // step 2: build array of links in format D3 expects
52 _.each(data, function (l) {
53 self.links.push({source:nl.indexOf(l['src-switch']),
54 target:nl.indexOf(l['dst-switch']),
55 value:10});
56 });
57 // console.log(self.nodes);
58 // console.log(self.links);
59 self.trigger('change');
60 //self.set(data);
61 }
62 });
63 }
64
65});