Merge "Add nemo-impl test file"
[nemo.git] / nemo-ui / src / main / resources / nemo / js / intentTopo.js
1 var IntentInfos='';\r
2 \r
3 function getIntentInfos(){\r
4           var userData=null;\r
5        jQuery.ajax({\r
6                         url: "/restconf/config/nemo-intent:users/",\r
7                         type: "GET",\r
8                         async: false,\r
9                         dataType: "json",\r
10                         success: function(data) {\r
11                                 console.log(data);\r
12                                 userData=data;\r
13                         },\r
14                         error: function(data) {\r
15                                 console.log(data);\r
16                                 alert('Get IntentInfo Error!');\r
17                         }\r
18                 });\r
19        return userData;\r
20      \r
21         }\r
22 \r
23  function getIntentDatas(){\r
24         var Datas=getIntentInfos();\r
25         if(!Datas){\r
26         Datas=userinfo;\r
27         }\r
28         IntentInfos=Datas;\r
29         //return virtualDatas;\r
30  }\r
31 \r
32 getIntentDatas();\r
33 \r
34  function getIntentInfoById(user_id,Data){\r
35                 //console.log(1);\r
36         if(!Data) Data=IntentInfos;\r
37         if(!Data) return;\r
38         if(typeof(Data)=='string'){\r
39     var user_json = JSON.parse(Data);\r
40     }\r
41     else\r
42     {\r
43     var user_json = Data;\r
44     }\r
45 \r
46      console.log(user_json);\r
47     var user_info = user_json['users']['user'];\r
48         for(var item in user_info){\r
49                 if(user_id==user_info[item]['user-id']){\r
50                         return user_info[item];\r
51                 }\r
52         }\r
53  }\r
54 \r
55  function getIntentInfoByName(user_name,Data){\r
56                 //console.log(1);\r
57         if(typeof(Data)=='string'){\r
58     var user_json = JSON.parse(Data);\r
59     }\r
60     else\r
61     {\r
62     var user_json = Data;\r
63     }\r
64     // console.log(user_json);\r
65     var user_info = user_json['users']['user'];\r
66         for(var item in user_info){\r
67                 if(user_name==user_info[item]['user-name']){\r
68                         return user_info[item];\r
69                 }\r
70         }\r
71  }\r
72 \r
73 \r
74 \r
75         function lead_policy(src_group, dest_group, flow_count_temp, color, id, chain_name, src_name, dest_name) {\r
76                 var cir_r = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("r"));\r
77 \r
78                 //get circle cx cy\r
79                 src_cx = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("cx"));\r
80                 src_cy = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("cy"));\r
81                 dest_cx = parseInt(jQuery("#" + dest_group + " circle:eq(0)").attr("cx"));\r
82                 dest_cy = parseInt(jQuery("#" + dest_group + " circle:eq(0)").attr("cy"));\r
83                 console.log(src_cx + "  " + src_cy + "  " + dest_cx + "   " + dest_cy);\r
84 \r
85                 //calculate deg\r
86                 var tri_h = dest_cx - src_cx;\r
87                 var tri_l = src_cy - dest_cy;\r
88                 var tri_s = Math.sqrt(tri_l * tri_l + tri_h * tri_h);\r
89                 var deg = Math.asin(tri_l / tri_s);\r
90                 console.log(tri_h + "  " + tri_l + "  " + tri_s);\r
91                 //alert(deg);\r
92                 console.log(deg);\r
93 \r
94 \r
95                 //calculate offset\r
96                 var offset = ((20 + (15 * parseInt(flow_count_temp))) / 180) * Math.PI;\r
97                 console.log("temp: " + flow_count_temp + " offset:  " + offset);\r
98 \r
99                 //calculate path possition\r
100                 var path_src_x, path_src_y, path_dest_x, path_dest_y, mid_x, mid_y, b_x, b_y;\r
101                 if (tri_h >= 0) {\r
102                         mid_x = src_cx + tri_h / 2;\r
103                         mid_y = src_cy - tri_l / 2;\r
104                         path_src_x = src_cx + cir_r * (Math.cos(offset + deg));\r
105                         path_src_y = src_cy - cir_r * (Math.sin(offset + deg));\r
106                         path_dest_x = dest_cx - (cir_r + 14) * (Math.cos(offset - deg));\r
107                         path_dest_y = dest_cy - (cir_r + 14) * (Math.sin(offset - deg));\r
108                         if (tri_l >= 0) {\r
109                                 b_x = mid_x - (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.sin(deg));;\r
110                                 b_y = mid_y - (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.cos(deg));\r
111                         } else {\r
112                                 b_x = mid_x + (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.sin(deg));\r
113                                 b_y = mid_y - (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.cos(deg));\r
114                         }\r
115 \r
116                 } else {\r
117                         mid_x = src_cx + tri_h / 2;\r
118                         mid_y = src_cy - tri_l / 2;\r
119                         path_src_x = src_cx - cir_r * (Math.cos(offset - deg));\r
120                         path_src_y = src_cy + cir_r * (Math.sin(offset - deg));\r
121                         path_dest_x = dest_cx + (cir_r + 14) * (Math.cos(-offset - deg));\r
122                         path_dest_y = dest_cy - (cir_r + 14) * (Math.sin(-offset - deg));\r
123                         if (tri_l >= 0) {\r
124                                 b_x = mid_x - (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.sin(deg));\r
125                                 b_y = mid_y + (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.cos(deg));\r
126                         } else {\r
127                                 b_x = mid_x + (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.sin(deg));\r
128                                 b_y = mid_y + (80 + 30 * parseInt(flow_count_temp)) * Math.abs(Math.cos(deg));\r
129                         }\r
130 \r
131                 }\r
132                 //path title\r
133                 var path_title = document.createElementNS('http://www.w3.org/2000/svg', 'path');\r
134 \r
135 \r
136 \r
137                 //create path\r
138                 var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');\r
139                 var path_main = jQuery(path).attr({\r
140                         id: id,\r
141                         node_start: src_name,\r
142                         node_end: dest_name,\r
143                         type: "flow",\r
144                         sx: path_src_x,\r
145                         sy: path_src_y,\r
146                         mx: b_x,\r
147                         my: b_y,\r
148                         ex: path_dest_x,\r
149                         ey: path_dest_y,\r
150                         count: flow_count_temp,\r
151                         via: chain_name,\r
152                         d: 'M' + path_src_x + " " + path_src_y + ' Q' + b_x + ' ' + b_y + ' ' + path_dest_x + ' ' + path_dest_y,\r
153                         'stroke': color,\r
154                         'stroke-width': 3,\r
155                         fill: "none",\r
156                         'stroke-dasharray': "6,6",\r
157                         'marker-end': "url(#idArrow2)",\r
158                         'marker-mid': "url(#idtext2)"\r
159                 });\r
160                 jQuery('#service_svg2').prepend(path_main);\r
161 \r
162         }\r
163 \r
164         function get_path_color() {\r
165                 while (1) {\r
166                         var num1 = Math.floor(Math.random() * 256);\r
167                         if (num1 > 220)\r
168                                 continue;\r
169                         return num1.toString();\r
170                 }\r
171         }\r
172 \r
173         function flow_get_end_name(src_ip, dest_ip) {\r
174                 var host_name = ['', ''];\r
175                 if (typeof(phy_host_ip[src_ip]) != "undefined")\r
176                         host_name[0] = phy_host_ip[src_ip];\r
177                 else {\r
178                         for (var find_ip_cursor = 0; find_ip_cursor < jQuery("#service_svg2 g").length; find_ip_cursor++) {\r
179                                 if (jQuery("#service_svg2 g:eq(" + find_ip_cursor + ")").attr("ip-prefix") == src_ip) {\r
180                                         host_name[0] = jQuery("#service_svg2 g:eq(" + find_ip_cursor + ")").attr("id");\r
181                                 }\r
182 \r
183                         }\r
184                 }\r
185                 if (typeof(phy_host_ip[dest_ip]) != "undefined")\r
186                         host_name[1] = phy_host_ip[dest_ip];\r
187                 else {\r
188                         for (var find_ip_cursor = 0; find_ip_cursor < jQuery("#service_svg2 g").length; find_ip_cursor++) {\r
189                                 if (jQuery("#service_svg2 g:eq(" + find_ip_cursor + ")").attr("ip-prefix") == dest_ip) {\r
190                                         host_name[1] = jQuery("#service_svg2 g:eq(" + find_ip_cursor + ")").attr("id");\r
191                                 }\r
192 \r
193                         }\r
194                 }\r
195                 console.log(host_name[0] + " " + host_name[1]);\r
196                 return host_name;\r
197 \r
198 \r
199         }\r
200 \r
201         function flow_get_group(src_ip, dest_ip) {\r
202                 var src_host_name = flow_get_end_name(src_ip, dest_ip)[0];\r
203                 var dest_host_name = flow_get_end_name(src_ip, dest_ip)[1];\r
204                 var group_node = ['', ''];\r
205                 for (var i = 0; i < jQuery("#service_svg2 g").length; i++) {\r
206                         host_list = jQuery("#service_svg2 g:eq(" + i + ")").attr("sub").split(",");\r
207                         console.log(host_list);\r
208                         if (host_list[0] == '') {\r
209                                 continue;\r
210                         }\r
211                         for (var j = 0; j < host_list.length; j++) {\r
212                                 if (host_list[j] == src_host_name) {\r
213                                         group_node[0] = jQuery("#service_svg2 g:eq(" + i + ")").attr("id");\r
214                                 }\r
215                                 if (host_list[j] == dest_host_name) {\r
216                                         group_node[1] = jQuery("#service_svg2 g:eq(" + i + ")").attr("id");\r
217                                 }\r
218                         }\r
219                         if (group_node[0] != '' && group_node[1] != '')\r
220                                 break;\r
221                 }\r
222                 console.log("node: " + group_node[0] + "  " + group_node[1]);\r
223                 return group_node;\r
224         }\r
225 \r
226         function draw_flow_data(src_ip, dest_ip, flow_name) {\r
227                 var src_group = flow_get_group(src_ip, dest_ip)[0];\r
228                 var dest_group = flow_get_group(src_ip, dest_ip)[1];\r
229                 //get flow count\r
230                 var flow_count_temp = 0;\r
231                 while (1) {\r
232                         var end_flag = 0;\r
233                         for (var find_count = 0; find_count < jQuery("#service_svg2 path").length; find_count++) {\r
234                                 if (jQuery("#service_svg2 path:eq(" + find_count + ")").attr("type") != "flow")\r
235                                         continue;\r
236                                 if (jQuery("#service_svg2 path:eq(" + find_count + ")").attr("node_start") == src_group && jQuery("#service_svg2 path:eq(" + find_count + ")").attr("node_end") == dest_group) {\r
237                                         if (flow_count_temp == jQuery("#service_svg2 path:eq(" + find_count + ")").attr("count")) {\r
238                                                 end_flag = 1;\r
239                                                 flow_count_temp++;\r
240                                                 break;\r
241                                         }\r
242 \r
243                                 }\r
244                         }\r
245                         if (end_flag != 1)\r
246                                 break;\r
247                 }\r
248 \r
249 \r
250 \r
251                 //get Radio\r
252                 var cir_r = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("r"));\r
253 \r
254 \r
255                 //get circle cx cy\r
256                 src_cx = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("cx"));\r
257                 src_cy = parseInt(jQuery("#" + src_group + " circle:eq(0)").attr("cy"));\r
258                 dest_cx = parseInt(jQuery("#" + dest_group + " circle:eq(0)").attr("cx"));\r
259                 dest_cy = parseInt(jQuery("#" + dest_group + " circle:eq(0)").attr("cy"));\r
260                 console.log(src_cx + "  " + src_cy + "  " + dest_cx + "   " + dest_cy);\r
261 \r
262                 //calculate deg\r
263                 var tri_h = dest_cx - src_cx;\r
264                 var tri_l = src_cy - dest_cy;\r
265                 var tri_s = Math.sqrt(tri_l * tri_l + tri_h * tri_h);\r
266                 var deg = Math.asin(tri_l / tri_s);\r
267                 console.log(tri_h + "  " + tri_l + "  " + tri_s);\r
268                 //alert(deg);\r
269                 console.log(deg);\r
270 \r
271 \r
272                 //calculate offset\r
273                 var offset = ((20 + (15 * flow_count_temp)) / 180) * Math.PI;\r
274                 console.log("offset:  " + offset);\r
275 \r
276                 //calculate path possition\r
277                 var path_src_x, path_src_y, path_dest_x, path_dest_y, mid_x, mid_y, b_x, b_y;\r
278                 if (tri_h >= 0) {\r
279                         mid_x = src_cx + tri_h / 2;\r
280                         mid_y = src_cy - tri_l / 2;\r
281                         path_src_x = src_cx + cir_r * (Math.cos(offset + deg));\r
282                         path_src_y = src_cy - cir_r * (Math.sin(offset + deg));\r
283                         path_dest_x = dest_cx - (cir_r + 14) * (Math.cos(offset - deg));\r
284                         path_dest_y = dest_cy - (cir_r + 14) * (Math.sin(offset - deg));\r
285                         if (tri_l >= 0) {\r
286                                 b_x = mid_x - (80 + 30 * flow_count_temp) * Math.abs(Math.sin(deg));;\r
287                                 b_y = mid_y - (80 + 30 * flow_count_temp) * Math.abs(Math.cos(deg));\r
288                         } else {\r
289                                 b_x = mid_x + (80 + 30 * flow_count_temp) * Math.abs(Math.sin(deg));\r
290                                 b_y = mid_y - (80 + 30 * flow_count_temp) * Math.abs(Math.cos(deg));\r
291                         }\r
292 \r
293                 } else {\r
294                         mid_x = src_cx + tri_h / 2;\r
295                         mid_y = src_cy - tri_l / 2;\r
296                         path_src_x = src_cx - cir_r * (Math.cos(offset - deg));\r
297                         path_src_y = src_cy + cir_r * (Math.sin(offset - deg));\r
298                         path_dest_x = dest_cx + (cir_r + 14) * (Math.cos(-offset - deg));\r
299                         path_dest_y = dest_cy - (cir_r + 14) * (Math.sin(-offset - deg));\r
300                         if (tri_l >= 0) {\r
301                                 b_x = mid_x - (80 + 30 * flow_count_temp) * Math.abs(Math.sin(deg));\r
302                                 b_y = mid_y + (80 + 30 * flow_count_temp) * Math.abs(Math.cos(deg));\r
303                         } else {\r
304                                 b_x = mid_x + (80 + 30 * flow_count_temp) * Math.abs(Math.sin(deg));\r
305                                 b_y = mid_y + (80 + 30 * flow_count_temp) * Math.abs(Math.cos(deg));\r
306                         }\r
307 \r
308                 }\r
309                 //path title\r
310                 var path_title = document.createElementNS('http://www.w3.org/2000/svg', 'path');\r
311 \r
312 \r
313 \r
314                 //create path\r
315                 var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');\r
316                 var path_main = jQuery(path).attr({\r
317                         id: flow_name,\r
318                         node_start: src_group,\r
319                         node_end: dest_group,\r
320                         type: "flow",\r
321                         sx: path_src_x,\r
322                         sy: path_src_y,\r
323                         mx: b_x,\r
324                         my: b_y,\r
325                         ex: path_dest_x,\r
326                         ey: path_dest_y,\r
327                         via: "none",\r
328                         count: flow_count_temp,\r
329                         d: 'M' + path_src_x + " " + path_src_y + ' Q' + b_x + ' ' + b_y + ' ' + path_dest_x + ' ' + path_dest_y,\r
330                         'stroke': "rgb(" + get_path_color() + "," + get_path_color() + "," + get_path_color() + ")",\r
331                         'stroke-width': 3,\r
332                         fill: "none",\r
333                         'stroke-dasharray': "6,6",\r
334                         'marker-end': "url(#idArrow2)",\r
335                         'marker-mid': "url(#idtext2)"\r
336                 });\r
337                 if (ne_flag == 0)\r
338                         jQuery(path).attr("stroke", "rgb(" + get_path_color() + "," + get_path_color() + "," + get_path_color() + ")");\r
339                 else if (ne_flag == 1)\r
340                         jQuery(path).attr("stroke", old_color);\r
341                 jQuery('#service_svg2').prepend(path_main);\r
342 \r
343 \r
344         }\r
345 \r
346         function draw_connection_data(conn_name, node_name_1, node_name_2, bandwidth) {\r
347                 if (conn_name != null && typeof(conn_name) != "undefined")\r
348                         jQuery("#" + conn_name).remove();\r
349                 try {\r
350                         var node_cx_1 = jQuery("#" + node_name_1 + "_group").attr("cx");\r
351                         var node_cy_1 = jQuery("#" + node_name_1 + "_group").attr("cy");\r
352                         var node_cx_2 = jQuery("#" + node_name_2 + "_group").attr("cx");\r
353                         var node_cy_2 = jQuery("#" + node_name_2 + "_group").attr("cy");\r
354                         //var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
355                         var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');\r
356                         var path_main = jQuery(path).attr({\r
357                                 id: conn_name,\r
358                                 node_start: node_name_1,\r
359                                 node_end: node_name_2,\r
360                                 type: "connection",\r
361                                 d: 'M' + node_cx_1 + " " + node_cy_1 + ' L' + node_cx_2 + ' ' + node_cy_2,\r
362                                 'stroke': "black",\r
363                                 'stroke-width': parseInt(bandwidth),\r
364                                 fill: "black"\r
365                         });\r
366                         jQuery('#service_svg2').prepend(path_main);\r
367                 } catch (err) {\r
368                         alert(err);\r
369                 }\r
370         }\r
371 \r
372         function redraw_node_possition_data() {\r
373                 node_count = jQuery("#service_svg2 g").length;\r
374                 if (node_count == 1) {\r
375                         var x = 550;\r
376                         var y = 450;\r
377                         dis_x = x - jQuery("#service_svg2 g:eq(0) circle:eq(0)").attr("cx");\r
378                         dis_y = y - jQuery("#service_svg2 g:eq(0) circle:eq(0)").attr("cy");\r
379                         jQuery("#service_svg2 g:eq(0) circle:eq(0)").attr("cx", x);\r
380                         jQuery("#service_svg2 g:eq(0) circle:eq(0)").attr("cy", y);\r
381                         for (var j = 0; j < jQuery("#service_svg2 g:eq(0) rect").length; j++) {\r
382                                 var last_x = parseInt(jQuery("#service_svg2 g:eq(0) rect:eq(" + j + ")").attr("x"));\r
383                                 var last_y = parseInt(jQuery("#service_svg2 g:eq(0) rect:eq(" + j + ")").attr("y"));\r
384                                 jQuery("#service_svg2 g:eq(0) rect:eq(" + j + ")").attr("x", last_x + dis_x);\r
385                                 jQuery("#service_svg2 g:eq(0) rect:eq(" + j + ")").attr("y", last_y + dis_y);\r
386                         }\r
387                         for (var j = 0; j < jQuery("#service_svg2 g:eq(0) text").length; j++) {\r
388                                 jQuery("#service_svg2 g:eq(0) text:eq(" + j + ")").attr("x", parseInt(jQuery("#service_svg2 g:eq(0) text:eq(" + j + ")").attr("x")) + dis_x);\r
389                                 jQuery("#service_svg2 g:eq(0) text:eq(" + j + ")").attr("y", parseInt(jQuery("#service_svg2 g:eq(0) text:eq(" + j + ")").attr("y")) + dis_y);\r
390                         }\r
391 \r
392                         return;\r
393 \r
394                 }\r
395                 var res = calculatePos(node_count);\r
396                 var r = 300;\r
397                 for (var i = 0; i < node_count; i++) {\r
398                         var deg = res[i];\r
399                         var x = 550 + Math.cos(deg) * r;\r
400                         var y = 450 - Math.sin(deg) * r;\r
401                         dis_x = x - parseInt(jQuery("#service_svg2 g:eq(" + i + ") circle:eq(0)").attr("cx"));\r
402                         dis_y = y - parseInt(jQuery("#service_svg2 g:eq(" + i + ") circle:eq(0)").attr("cy"));\r
403                         jQuery("#service_svg2 g:eq(" + i + ") circle:eq(0)").attr("cx", x);\r
404                         jQuery("#service_svg2 g:eq(" + i + ") circle:eq(0)").attr("cy", y);\r
405                         for (var j = 0; j < jQuery("#service_svg2 g:eq(" + i + ") rect").length; j++) {\r
406                                 jQuery("#service_svg2 g:eq(" + i + ") rect:eq(" + j + ")").attr("x", parseInt(jQuery("#service_svg2 g:eq(" + i + ") rect:eq(" + j + ")").attr("x")) + dis_x);\r
407                                 jQuery("#service_svg2 g:eq(" + i + ") rect:eq(" + j + ")").attr("y", parseInt(jQuery("#service_svg2 g:eq(" + i + ") rect:eq(" + j + ")").attr("y")) + dis_y);\r
408                         }\r
409                         for (var j = 0; j < jQuery("#service_svg2 g:eq(" + i + ") text").length; j++) {\r
410                                 jQuery("#service_svg2 g:eq(" + i + ") text:eq(" + j + ")").attr("x", parseInt(jQuery("#service_svg2 g:eq(" + i + ") text:eq(" + j + ")").attr("x")) + dis_x);\r
411                                 jQuery("#service_svg2 g:eq(" + i + ") text:eq(" + j + ")").attr("y", parseInt(jQuery("#service_svg2 g:eq(" + i + ") text:eq(" + j + ")").attr("y")) + dis_y);\r
412                         }\r
413 \r
414                 }\r
415 \r
416         }\r
417 \r
418         function draw_group_data(node_name, node_number, node_list, node_type, ip) {\r
419                 // alert("type:"+node_type);\r
420                 var circle_x = 550;\r
421                 var circle_y = 450;\r
422                 if (node_number == 0) {\r
423                         var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
424                         var circle_main = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\r
425                         var inCircle1_main = jQuery(circle_main).attr({\r
426                                 id: node_name + "_group",\r
427                                 cx: circle_x,\r
428                                 cy: circle_y,\r
429                                 r: 90,\r
430                                 'stroke': "black",\r
431                                 'stroke-width': 3,\r
432                                 fill: "white"\r
433                         });\r
434                         var text1 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
435                         var text1_main = jQuery(text1).attr({\r
436                                 id: node_name + "_title1",\r
437                                 x: circle_x,\r
438                                 y: circle_y - 8,\r
439                                 fill: "black",\r
440                                 'text-anchor': 'middle',\r
441                                 "stroke": "black",\r
442                                 "stroke-width": 0.8\r
443 \r
444                         });\r
445                         jQuery(text1).text(node_type);\r
446                         var text2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
447                         var text2_main = jQuery(text2).attr({\r
448                                 id: node_name + "_title2",\r
449                                 x: circle_x,\r
450                                 y: circle_y + 10,\r
451                                 fill: "                       ",\r
452                                 'text-anchor': 'middle'\r
453                         });\r
454                         jQuery(text2).text(node_name);\r
455                         var g_main = jQuery(g).append(inCircle1_main);\r
456                         jQuery(g).append(text1_main);\r
457                         jQuery(g).append(text2_main);\r
458                         jQuery(g).attr("id", node_name);\r
459                         jQuery(g).attr("type", node_type);\r
460                         if (node_type != "ext-group")\r
461                                 jQuery(g).attr("sub", "");\r
462                         else {\r
463                                 jQuery(g).attr("sub", node_name);\r
464                                 jQuery(g).attr("ip-prefix", ip);\r
465                                 //ext_ip[jQuery("#ext-group_ip-prefix").val().trim()] = jQuery("#node_name").val().trim();\r
466 \r
467                         }\r
468                         if (node_type.indexOf("chain") > -1)\r
469                                 jQuery(g).attr("flow", 0);\r
470                         console.log(g_main);\r
471                         jQuery('#service_svg2').append(g_main);\r
472                         console.log(jQuery('#service_svg2').html())\r
473                 } else if (node_number == 1) {\r
474                         var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
475                         var circle_main = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\r
476                         var inCircle1_main = jQuery(circle_main).attr({\r
477                                 id: node_name + "_group",\r
478                                 cx: circle_x,\r
479                                 cy: circle_y,\r
480                                 r: 90,\r
481                                 'stroke': "black",\r
482                                 'stroke-width': 3,\r
483                                 fill: "white"\r
484                         });\r
485                         var host1 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
486                         var host1_main = jQuery(host1).attr({\r
487                                 id: node_list[0],\r
488                                 x: circle_x - 57,\r
489                                 y: circle_y - 25,\r
490                                 width: 114,\r
491                                 height: 50,\r
492                                 'stroke': "black",\r
493                                 'stroke-width': 1,\r
494                                 fill: "white"\r
495                         });\r
496                         var text1 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
497                         var text1_main = jQuery(text1).attr({\r
498                                 id: node_name + "_title1",\r
499                                 x: circle_x,\r
500                                 y: circle_y - 48,\r
501                                 fill: "black",\r
502                                 'text-anchor': 'middle',\r
503                                 "stroke": "black",\r
504                                 "stroke-width": 0.8\r
505                         });\r
506                         jQuery(text1).text(node_type);\r
507                         var text2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
508                         var text2_main = jQuery(text2).attr({\r
509                                 id: node_name + "_title2",\r
510                                 x: circle_x,\r
511                                 y: circle_y - 30,\r
512                                 fill: "black",\r
513                                 'text-anchor': 'middle'\r
514                         });\r
515                         jQuery(text2).text(node_name);\r
516                         var text3 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
517                         var text3_main = jQuery(text3).attr({\r
518                                 id: node_list[0] + '_text',\r
519                                 x: circle_x,\r
520                                 y: circle_y,\r
521                                 fill: "black",\r
522                                 'text-anchor': 'middle'\r
523                         });\r
524                         jQuery(text3).text(node_list[0]);\r
525                         var g_main = jQuery(g).append(inCircle1_main);\r
526                         jQuery(g).append(host1_main);\r
527                         jQuery(g).append(text1_main);\r
528                         jQuery(g).append(text2_main);\r
529                         jQuery(g).append(text3_main);\r
530                         jQuery(g).attr("id", node_name);\r
531                         jQuery(g).attr("type", node_type);\r
532                         jQuery(g).attr("sub", node_list[0]);\r
533                         if (node_type.indexOf("chain") > -1)\r
534                                 jQuery(g).attr("flow", 0);\r
535                         jQuery('#service_svg2').append(g_main);\r
536                 } else if (node_number == 2) {\r
537                         var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
538                         var circle_main = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\r
539                         var inCircle1_main = jQuery(circle_main).attr({\r
540                                 id: node_name + "_group",\r
541                                 cx: circle_x,\r
542                                 cy: circle_y,\r
543                                 r: 90,\r
544                                 'stroke': "black",\r
545                                 'stroke-width': 3,\r
546                                 fill: "white"\r
547                         });\r
548                         var host1 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
549                         var host1_main = jQuery(host1).attr({\r
550                                 id: node_list[0],\r
551                                 x: circle_x - 55,\r
552                                 y: circle_y - 25,\r
553                                 width: 110,\r
554                                 height: 34,\r
555                                 'stroke': "black",\r
556                                 'stroke-width': 1,\r
557                                 fill: "white"\r
558                         });\r
559                         var host2 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
560                         var host2_main = jQuery(host2).attr({\r
561                                 id: node_list[1],\r
562                                 x: circle_x - 55,\r
563                                 y: circle_y + 18,\r
564                                 width: 110,\r
565                                 height: 34,\r
566                                 'stroke': "black",\r
567                                 'stroke-width': 1,\r
568                                 fill: "white"\r
569                         });\r
570                         var text1 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
571                         var text1_main = jQuery(text1).attr({\r
572                                 id: node_name + "_title1",\r
573                                 x: circle_x,\r
574                                 y: circle_y - 48,\r
575                                 fill: "black",\r
576                                 'text-anchor': 'middle',\r
577                                 "stroke": "black",\r
578                                 "stroke-width": 0.8\r
579                         });\r
580                         jQuery(text1).text(node_type);\r
581                         var text2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
582                         var text2_main = jQuery(text2).attr({\r
583                                 id: node_name + "_title2",\r
584                                 x: circle_x,\r
585                                 y: circle_y - 31,\r
586                                 fill: "black",\r
587                                 'text-anchor': 'middle'\r
588                         });\r
589                         jQuery(text2).text(node_name);\r
590                         var text3 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
591                         var text3_main = jQuery(text3).attr({\r
592                                 id: node_list[0] + "_text",\r
593                                 x: circle_x,\r
594                                 y: circle_y - 5,\r
595                                 fill: "black",\r
596                                 'text-anchor': 'middle'\r
597                         });\r
598                         jQuery(text3).text(node_list[0]);\r
599                         var text4 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
600                         var text4_main = jQuery(text4).attr({\r
601                                 id: node_list[1] + "_text",\r
602                                 x: circle_x,\r
603                                 y: circle_y + 40,\r
604                                 fill: "black",\r
605                                 'text-anchor': 'middle'\r
606                         });\r
607                         jQuery(text4).text(node_list[1]);\r
608                         var g_main = jQuery(g).append(inCircle1_main);\r
609                         jQuery(g).append(host1_main);\r
610                         jQuery(g).append(host2_main);\r
611                         jQuery(g).append(text1_main);\r
612                         jQuery(g).append(text2_main);\r
613                         jQuery(g).append(text3_main);\r
614                         jQuery(g).append(text4_main);\r
615                         jQuery(g).attr("id", node_name);\r
616                         jQuery(g).attr("type", node_type);\r
617                         jQuery(g).attr("sub", node_list[0] + "," + node_list[1]);\r
618                         if (node_type.indexOf("chain") > -1)\r
619                                 jQuery(g).attr("flow", 0);\r
620                         jQuery('#service_svg2').append(g);\r
621 \r
622                 } else if (node_number == 3) {\r
623                         var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
624                         var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\r
625                         var circle_main = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\r
626                         var inCircle1_main = jQuery(circle_main).attr({\r
627                                 id: node_name + "_group",\r
628                                 cx: circle_x,\r
629                                 cy: circle_y,\r
630                                 r: 90,\r
631                                 'stroke': "black",\r
632                                 'stroke-width': 3,\r
633                                 fill: "white"\r
634                         });\r
635                         var host1 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
636                         var host1_main = jQuery(host1).attr({\r
637                                 id: node_list[0],\r
638                                 x: circle_x - 55,\r
639                                 y: circle_y - 31,\r
640                                 width: 110,\r
641                                 height: 25,\r
642                                 'stroke': "black",\r
643                                 'stroke-width': 1,\r
644                                 fill: "white"\r
645                         });\r
646                         var host2 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
647                         var host2_main = jQuery(host2).attr({\r
648                                 id: node_list[1],\r
649                                 x: circle_x - 55,\r
650                                 y: circle_y - 3,\r
651                                 width: 110,\r
652                                 height: 25,\r
653                                 'stroke': "black",\r
654                                 'stroke-width': 1,\r
655                                 fill: "white"\r
656                         });\r
657                         var host3 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');\r
658                         var host3_main = jQuery(host3).attr({\r
659                                 id: node_list[2],\r
660                                 x: circle_x - 55,\r
661                                 y: circle_y + 27,\r
662                                 width: 110,\r
663                                 height: 25,\r
664                                 'stroke': "black",\r
665                                 'stroke-width': 1,\r
666                                 fill: "white"\r
667                         });\r
668                         var text1 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
669                         var text1_main = jQuery(text1).attr({\r
670                                 id: node_name + "_title1",\r
671                                 x: circle_x,\r
672                                 y: circle_y - 51,\r
673                                 fill: "black",\r
674                                 'text-anchor': 'middle',\r
675                                 "stroke": "black",\r
676                                 "stroke-width": 0.8\r
677                         });\r
678                         jQuery(text1).text(node_type);\r
679                         var text2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
680                         var text2_main = jQuery(text2).attr({\r
681                                 id: node_name + "_title2",\r
682                                 x: circle_x,\r
683                                 y: circle_y - 36,\r
684                                 fill: "black",\r
685                                 'text-anchor': 'middle'\r
686                         });\r
687                         jQuery(text2).text(node_name);\r
688                         var text3 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
689                         var text3_main = jQuery(text3).attr({\r
690                                 id: node_list[0] + '_text',\r
691                                 x: circle_x,\r
692                                 y: circle_y - 13,\r
693                                 fill: "black",\r
694                                 'text-anchor': 'middle'\r
695                         });\r
696                         jQuery(text3).text(node_list[0]);\r
697                         var text4 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
698                         var text4_main = jQuery(text4).attr({\r
699                                 id: node_list[1] + '_text',\r
700                                 x: circle_x,\r
701                                 y: circle_y + 13,\r
702                                 fill: "black",\r
703                                 'text-anchor': 'middle'\r
704                         });\r
705                         jQuery(text4).text(node_list[1]);\r
706                         var text5 = document.createElementNS('http://www.w3.org/2000/svg', 'text');\r
707                         var text5_main = jQuery(text5).attr({\r
708                                 id: node_list[2] + '_text',\r
709                                 x: circle_x,\r
710                                 y: circle_y + 43,\r
711                                 fill: "black",\r
712                                 'text-anchor': 'middle'\r
713                         });\r
714                         jQuery(text5).text(node_list[2]);\r
715                         var g_main = jQuery(g).append(inCircle1_main);\r
716                         jQuery(g).append(host1_main);\r
717                         jQuery(g).append(host2_main);\r
718                         jQuery(g).append(host3_main);\r
719                         jQuery(g).append(text1_main);\r
720                         jQuery(g).append(text2_main);\r
721                         jQuery(g).append(text3_main);\r
722                         jQuery(g).append(text4_main);\r
723                         jQuery(g).append(text5_main);\r
724                         jQuery(g).attr("id", node_name);\r
725                         jQuery(g).attr("type", node_type);\r
726                         jQuery(g).attr("sub", node_list[0] + "," + node_list[1] + "," + node_list[2]);\r
727                         if (node_type.indexOf("chain") > -1)\r
728                                 jQuery(g).attr("flow", 0);\r
729                         jQuery('#service_svg2').append(g);\r
730                 }\r
731         }\r
732 \r
733         function analyjson_topo(user_data) {\r
734             //jQuery("#service_svg2").show();\r
735                 //jQuery("#service_svg").hide();\r
736                 //jQuery("#graph").hide();\r
737                 //jQuery("#service_svg").empty();\r
738                 // var username = jQuery("#getUserName").val();\r
739                 //alert(username);\r
740                 var html_init = '<defs><marker id="idArrow2" viewBox="0 0 20 20" refX="0" refY="10" markerUnits="strokeWidth" markerWidth="6" markerHeight="15" orient="auto"><path d="M 0 0 L 20 10 L0 20 z"fill="purple"stroke="black"/> </marker>\\r
741                     <marker id="idtext2" viewBox="0 0 120 50" refX="0" refY="0" markerUnits="strokeWidth" markerWidth="20" markerHeight="20"  orient="auto"><text style="font-family:sans-serif; font-size:14pt;"  x="20" y="20">text</text></marker></defs>';\r
742                 jQuery("#service_svg2").html(html_init);\r
743                 //var topo_data;\r
744                 //  jQuery.ajax({\r
745                 //      url: "/restconf/config/nemo-intent:users/",\r
746                 //      type: "GET",\r
747                 //      async: false,\r
748                 //      dataType: "json",\r
749                 //      success: function(data) {\r
750                 //              console.log(data);\r
751                 //              topo_data = data;\r
752                 //      },\r
753                 //      error: function(data) {\r
754                 //              console.log(data);\r
755                 //      }\r
756                 // });\r
757 \r
758                 //var name_data_list = topo_data["users"]["user"];\r
759 \r
760                 //var user_json_data, user_data;\r
761                 // for (var i in name_data_list) {\r
762                 //      if (name_data_list[i]["user-name"] == username) {\r
763                 //              user_data = name_data_list[i];\r
764                 //              user_json_data = name_data_list[i]["objects"];\r
765                 //              break;\r
766                 //      }\r
767                 // }\r
768 \r
769                 var user_json_data = user_data['objects'];\r
770                 if (user_json_data == null)\r
771                         return;\r
772 \r
773                 //host\r
774                 var host_list = [];\r
775                 for (var host_cursor in user_json_data["node"]) {\r
776                         if (user_json_data["node"][host_cursor]["node-type"] != "host")\r
777                                 continue;\r
778                         host_list[user_json_data["node"][host_cursor]["node-id"]] = user_json_data["node"][host_cursor]["node-name"];\r
779 \r
780                 }\r
781 \r
782                 //vas\r
783                 var vas_list = [];\r
784                 for (var vas_cursor in user_json_data["node"]) {\r
785                         if (user_json_data["node"][vas_cursor]["node-type"] != "cache" && user_json_data["node"][vas_cursor]["node-type"] != "fw" && user_json_data["node"][vas_cursor]["node-type"] != "lb")\r
786                                 continue;\r
787 \r
788                         vas_list[user_json_data["node"][vas_cursor]["node-id"]] = user_json_data["node"][vas_cursor]["node-name"];\r
789 \r
790                 }\r
791         \r
792 \r
793                 //group\r
794                 var node_list = [];\r
795 \r
796                 //l2/l3-group\r
797                 for (var lgroup_cursor in user_json_data["node"]) {\r
798                         if (user_json_data["node"][lgroup_cursor]["node-type"] != "l2-group" && user_json_data["node"][lgroup_cursor]["node-type"] != "l3-group")\r
799                                 continue;\r
800                         var sub_count = 0;\r
801                         var sub_list = [];\r
802                         for (var sub_cursor in user_json_data["node"][lgroup_cursor]["sub-node"]) {\r
803                                 sub_list[sub_count] = host_list[user_json_data["node"][lgroup_cursor]["sub-node"][sub_cursor]["node-id"]];\r
804                                 sub_count++;\r
805                         }\r
806                         draw_group_data(user_json_data["node"][lgroup_cursor]["node-name"], sub_list.length, sub_list, user_json_data["node"][lgroup_cursor]["node-type"], "");\r
807                         redraw_node_possition_data();\r
808                         node_list[user_json_data["node"][lgroup_cursor]["node-id"]] = user_json_data["node"][lgroup_cursor]["node-name"];\r
809                 }\r
810                 //chain_group\r
811                 for (var cgroup_cursor in user_json_data["node"]) {\r
812 \r
813                         if (user_json_data["node"][cgroup_cursor]["node-type"] != "chain-group")\r
814                                 continue;\r
815                         //alert("chain");\r
816                         var sub_count = 0;\r
817                         var sub_list = [];\r
818                         for (var sub_cursor in user_json_data["node"][cgroup_cursor]["sub-node"]) {\r
819                                 //alert(user_json_data["node"][cgroup_cursor]["sub-node"][sub_cursor]["node-id"]);\r
820                                 sub_list[sub_count] = vas_list[user_json_data["node"][cgroup_cursor]["sub-node"][sub_cursor]["node-id"]];\r
821                                 sub_count++;\r
822                         }\r
823                         //alert();\r
824                         draw_group_data(user_json_data["node"][cgroup_cursor]["node-name"], sub_list.length, sub_list, user_json_data["node"][cgroup_cursor]["node-type"], "");\r
825                         redraw_node_possition_data();\r
826                         node_list[user_json_data["node"][cgroup_cursor]["node-id"]] = user_json_data["node"][cgroup_cursor]["node-name"];\r
827                 }\r
828                 //ext-group\r
829                 for (var egroup_cursor in user_json_data["node"]) {\r
830                         if (user_json_data["node"][egroup_cursor]["node-type"] != "ext-group")\r
831                                 continue;\r
832                         // alert("ext");\r
833                         var ip;\r
834                         for (var ip_cursor in user_json_data["node"][egroup_cursor]["property"]) {\r
835                                 if (user_json_data["node"][egroup_cursor]["property"][ip_cursor]["property-name"] == "ip-prefix") {\r
836                                         ip = user_json_data["node"][egroup_cursor]["property"][ip_cursor]["property-values"]["string-value"][0]["value"];\r
837                                 }\r
838                         }\r
839                         draw_group_data(user_json_data["node"][egroup_cursor]["node-name"], 0, '', user_json_data["node"][egroup_cursor]["node-type"], ip);\r
840                         redraw_node_possition_data();\r
841                         node_list[user_json_data["node"][egroup_cursor]["node-id"]] = user_json_data["node"][egroup_cursor]["node-name"];\r
842                 }\r
843           // console.log(node_list);\r
844                 //connection\r
845                 for (var conn_cursor in user_json_data["connection"]) {\r
846                         var start_name = node_list[user_json_data["connection"][conn_cursor]["end-node"][0]["node-id"]];\r
847                         var end_name = node_list[user_json_data["connection"][conn_cursor]["end-node"][1]["node-id"]];\r
848                         var bandwidth\r
849                         if (user_json_data["connection"][conn_cursor]["property"] != null)\r
850                                 bandwidth = user_json_data["connection"][conn_cursor]["property"][0]["property-values"]["int-value"][0]["value"];\r
851                         else\r
852                                 bandwidth = 100;\r
853                         draw_connection_data(user_json_data["connection"][conn_cursor]["connection-name"], start_name, end_name, bandwidth / 100);\r
854                 }\r
855 \r
856                 //flow\r
857                 if (user_json_data["flow"] != null) {\r
858                         var flow_list = [];\r
859                         for (var flow_cursor in user_json_data["flow"]) {\r
860                                 var src_ip, dst_ip;\r
861                                 for (var match_cursor in user_json_data["flow"][flow_cursor]["match-item"]) {\r
862                                         if (user_json_data["flow"][flow_cursor]["match-item"][match_cursor]["match-item-name"] == "dst-ip") {\r
863                                                 dst_ip = user_json_data["flow"][flow_cursor]["match-item"][match_cursor]["match-item-value"]["string-value"];\r
864                                         }\r
865                                         if (user_json_data["flow"][flow_cursor]["match-item"][match_cursor]["match-item-name"] == "src-ip") {\r
866                                                 src_ip = user_json_data["flow"][flow_cursor]["match-item"][match_cursor]["match-item-value"]["string-value"];\r
867                                         }\r
868                                 }\r
869                                 draw_flow_data(src_ip, dst_ip, user_json_data["flow"][flow_cursor]["flow-name"]);\r
870                                 flow_list[user_json_data["flow"][flow_cursor]["flow-id"]] = user_json_data["flow"][flow_cursor]["flow-name"]\r
871                         }\r
872 \r
873                 }\r
874                 //operation\r
875                 if (user_data["operations"] != null) {\r
876                         for (var operation_cursor in user_data["operations"]["operation"]) {\r
877                                 var flow_name = flow_list[user_data["operations"]["operation"][operation_cursor]["target-object"]];\r
878                                 var chain_name = node_list[user_data["operations"]["operation"][operation_cursor]["action"][0]["parameter-values"]["string-value"][0]["value"]];\r
879                                 var node_start = jQuery("#" + flow_name).attr("node_start");\r
880                                 var node_end = jQuery("#" + flow_name).attr("node_end");\r
881                                 var c1_flag = 0;\r
882                                 var c2_flag = 0;\r
883                                 for (var i = 0; i < jQuery("#service_svg2 path").length; i++) {\r
884                                         if (jQuery("#service_svg2 path:eq(" + i + ")").attr("type") == "connection") {\r
885                                                 var node_name_old_1 = jQuery("#service_svg2 path:eq(" + i + ")").attr("node_start");\r
886                                                 var node_name_old_2 = jQuery("#service_svg2 path:eq(" + i + ")").attr("node_end");\r
887                                                 console.log("old:" + node_name_old_1 + "  " + node_name_old_2);\r
888                                                 if (((node_start == node_name_old_1) && (chain_name == node_name_old_2)) || ((node_start == node_name_old_2) && (chain_name == node_name_old_1))) {\r
889                                                         c1_flag = 1;\r
890                                                 }\r
891                                         }\r
892                                 }\r
893                                 for (var i = 0; i < jQuery("#service_svg2 path").length; i++) {\r
894                                         if (jQuery("#service_svg2 path:eq(" + i + ")").attr("type") == "connection") {\r
895                                                 var node_name_old_1 = jQuery("#service_svg2 path:eq(" + i + ")").attr("node_start");\r
896                                                 var node_name_old_2 = jQuery("#service_svg2 path:eq(" + i + ")").attr("node_end");\r
897                                                 console.log("old:" + node_name_old_1 + "  " + node_name_old_2);\r
898                                                 if (((node_end == node_name_old_1) && (chain_name == node_name_old_2)) || ((node_end == node_name_old_2) && (chain_name == node_name_old_1))) {\r
899                                                         c2_flag = 1;\r
900                                                 }\r
901                                         }\r
902                                 }\r
903                                 if (c2_flag == 0 || c2_flag == 0) {\r
904                                         alert("No connection!");\r
905                                         return;\r
906                                 }\r
907                                 lead_policy(node_start, chain_name, parseInt(jQuery("#" + flow_name).attr("count")), jQuery("#" + flow_name).attr("stroke"), flow_name + "_1", chain_name, node_start, node_end)\r
908                                 lead_policy(chain_name, node_end, parseInt(jQuery("#" + flow_name).attr("count")), jQuery("#" + flow_name).attr("stroke"), flow_name + "_2", chain_name, node_start, node_end)\r
909                                 jQuery("#" + flow_name).remove();\r
910 \r
911 \r
912 \r
913                         }\r
914 \r
915                 }\r
916         }\r
917 \r
918         //parse nemo language\r
919         function parseNemoLan(userinfo) {\r
920                 console.log(userinfo);\r
921                 var userJsonString = JSON.stringify(userinfo);\r
922                 var userJson = JSON.parse(userJsonString);\r
923                 // console.log(userJson);\r
924                 var user_data = userinfo;\r
925                 //set host nodes connection and flow array  array[id]-->name\r
926                 var host = [];\r
927                 var nodes = [];\r
928                 var connection = [];\r
929                 var flow = [];\r
930                 for (var i in user_data) {\r
931                         // console.log(i);\r
932                         if (i == 'objects') {\r
933                                 for (var j in user_data['objects']) {\r
934                                         // console.log(j);\r
935                                         if (j == 'node') {\r
936                                                 for (var k in user_data[i][j]) {\r
937                                                         nodes[user_data[i][j][k]["node-id"]] = user_data[i][j][k]["node-name"];\r
938                                                 }\r
939                                         } else if (j == 'connection') {\r
940                                                 for (var k in user_data[i][j]) {\r
941                                                         connection[user_data[i][j][k]["connection-id"]] = user_data[i][j][k]["connection-name"];\r
942                                                 }\r
943                                         } else if (j == 'flow') {\r
944                                                 for (var k in user_data[i][j]) {\r
945                                                         flow[user_data[i][j][k]["flow-id"]] = user_data[i][j][k]["flow-name"];\r
946                                                 }\r
947                                         }\r
948                                 }\r
949                         } else if (i == 'operations') {\r
950 \r
951                         }\r
952                 }\r
953                 console.log(nodes);\r
954                 console.log(connection);\r
955                 console.log(flow);\r
956                 //parse and show nemo language(node connection flow operation)\r
957                 for (var i in user_data["objects"]) {\r
958                         if (i == "node") {\r
959                                 var nodeNemo = [];\r
960                                 var node = user_data["objects"]['node'];\r
961                                 for (var j in node) {\r
962                                         var nemo_str='';\r
963                                         if(node[j]['node-type']=='host'){\r
964                                                  nemo_str += "Import Node  " + node[j]['node-name'] + " Type " + node[j]['node-type'];\r
965                                         }else{\r
966                                                  nemo_str += "Create Node  " + node[j]['node-name'] + " Type " + node[j]['node-type'];\r
967                                         }                                       \r
968                                         var sub_node = node[j]['sub-node'];\r
969                                         if (sub_node && sub_node.length > 0) {\r
970                                                 nemo_str += ' Contain ';\r
971                                                 for (var k in sub_node) {\r
972                                                         nemo_str += nodes[sub_node[k]['node-id']] + ',';\r
973                                                 }\r
974                                                 nemo_str = nemo_str.substring(0, nemo_str.length - 1);\r
975                                         }\r
976                                         var property = node[j]['property'];\r
977                                         if (property && property.length > 0) {\r
978                                                 nemo_str += ' Property ';\r
979                                                 for (var k in property) {\r
980                                                         nemo_str += property[k]['property-name'] + ':"' + property[k]['property-values']['string-value'][0]['value'] + '",';\r
981                                                 }\r
982                                                 nemo_str = nemo_str.substring(0, nemo_str.length - 1);\r
983                                         }\r
984                                         nodeNemo.push(nemo_str);\r
985                                 }\r
986                                 for (var item in nodeNemo) {\r
987                                         // alert(jQuery("#nemo_str_show").html);\r
988                                         jQuery("#nemo_str_show").append('<p>'+nodeNemo[item]+'&nbsp;&nbsp;'+'</p>');\r
989                                 }\r
990                                 console.log(nodeNemo);\r
991                         } \r
992 \r
993                         else if (i == "connection") {\r
994                                 var connectionNemo = [];\r
995                                 var conn = user_data["objects"]['connection'];\r
996                                 for (var j in conn) {\r
997                                         var nemo_str = "Create Connection " + conn[j]['connection-name'] + ' Type ' + conn[j]['connection-type'];\r
998                                         nemo_str += " Endnodes " + nodes[conn[j]['end-node'][0]['node-id']] + ',' + nodes[conn[j]['end-node'][1]['node-id']];\r
999                                     var property = conn[j]['property'];\r
1000                                     if(property&&property.length>0){\r
1001                                         nemo_str+=" Property";\r
1002                                     for(var k in property){\r
1003                                         nemo_str+=' '+property[k]['property-name']+':"';\r
1004                                         var property_value=property[k]['property-values'];\r
1005                                         console.log(property_value);\r
1006                                         for(var v in property_value){//int-value or string-value\r
1007                                                 nemo_str+=property_value[v][0]['value'];\r
1008                                         }\r
1009                                         nemo_str+='",';\r
1010                                     }\r
1011                                         nemo_str = nemo_str.substring(0,nemo_str.length-1);\r
1012                                 }\r
1013 \r
1014                                         connectionNemo.push(nemo_str);\r
1015                                 }\r
1016                                 for (var item in connectionNemo) {\r
1017                                         // alert(jQuery("#nemo_str_show").html);\r
1018                                         jQuery("#nemo_str_show").append('<p>'+connectionNemo[item]+'&nbsp;&nbsp;'+'</p>');\r
1019                                 }\r
1020                                 console.log(connectionNemo);\r
1021                         } \r
1022 \r
1023                         else if (i = 'flow') {\r
1024                                 var flowNemo = [];\r
1025                                 var fl = user_data["objects"]['flow'];\r
1026                                 for (var j in fl) {\r
1027                                         var nemo_str = 'Create Flow ' + fl[j]['flow-name'];\r
1028                                         var match = fl[j]["match-item"];\r
1029                                         if (match && match.length > 0) {\r
1030                                                 nemo_str += " Match ";\r
1031                                                 for (var k in match) {\r
1032                                                         nemo_str += match[k]['match-item-name'] + ':"' + match[k]["match-item-value"]['string-value'] + '",';\r
1033                                                 }\r
1034                                                 nemo_str = nemo_str.substring(0, nemo_str.length - 1);\r
1035                                         }\r
1036                                         flowNemo.push(nemo_str);\r
1037                                 }\r
1038 \r
1039                                 for (var item in flowNemo) {\r
1040                                         // alert(jQuery("#nemo_str_show").html);\r
1041                                         jQuery("#nemo_str_show").append('<p>'+flowNemo[item]+'&nbsp;&nbsp;'+'</p>');\r
1042                                 }\r
1043                                 console.log(flowNemo);\r
1044                         }\r
1045                 }\r
1046 \r
1047 \r
1048                 for (var i in user_data["operations"]) {\r
1049                         var opNemo = [];\r
1050                         var operation = user_data["operations"]['operation'];\r
1051                         for (var j in operation) {\r
1052                                 var nemo_str = 'Create Operation ' + operation[j]["operation-name"];\r
1053                                 // console.log(flow[operation[j]['target-object']]);\r
1054                                 nemo_str += ' Target ' + flow[operation[j]['target-object']];\r
1055                                 var action = operation[j]['action'];\r
1056                                 if (action && action.length > 0) {\r
1057                                         nemo_str += " Action "\r
1058                                         for (var k in action) {\r
1059                                                 nemo_str += action[k]['action-name'] + ":" + nodes[action[k]['parameter-values']["string-value"][0]['value']] + ',';\r
1060                                         }\r
1061                                         nemo_str = nemo_str.substring(0, nemo_str.length - 1);\r
1062                                 }\r
1063                                 opNemo.push(nemo_str);\r
1064                         }\r
1065                                 for (var item in opNemo) {\r
1066                                         // alert(jQuery("#nemo_str_show").html);\r
1067                                         jQuery("#nemo_str_show").append('<p>'+opNemo[item]+'&nbsp;&nbsp;'+'</p>');\r
1068                                 }\r
1069                         console.log(opNemo);\r
1070                 }\r
1071         }\r
1072 \r
1073         jQuery(function($){\r
1074                 // var user_data = userinfo['users']['user'][0];\r
1075                 // // console.log(JSON.stringify(user_data));\r
1076                 // analyjson_topo(user_data);\r
1077                 // parseNemoLan(user_data);\r
1078   //       //set keyWords style\r
1079                 // $("#nemo_str_show p").each(function(){\r
1080                 //      var $res=$(this);\r
1081                 //      keyWords.forEach(function(item,index,array){\r
1082                 //              // console.log(item);\r
1083                 //              $res.html($res.html().replace(item,"<span class='keyWords'>"+item+"</span>"));\r
1084                 //      });\r
1085                 //      // console.log($res.html());\r
1086                 // });\r
1087 \r
1088         });\r
1089