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