Teaches you to draw the entire Vietnam backbone routing topology per minute

Source: Internet
Author: User

A headline party, at the first point a big headline to attract you crossing come.

In fact, the principle is very easy, our job is to do some data processing, the final generation of KML script is now on Google Earth.

Access to Special topics:

First, the data source http://www.caida.org. This is an Internet data analysis cooperation Organization, the data is more authoritative, the world's many networks of scientific research data from this.

The practical information for this article is here: http://www.caida.org/data/internet-topology-data-kit/This is the topological information data of some Internet. And every six months around the update.

Get the latest version number from here:


Go in and go to this place: what http://data.caida.org/datasets/topology/ark/ipv4/itdk/2011-10/saw:



The data is divided into two groups, which are obtained using different tools and probing methods. Each is increased using kapar and does not increase. The difference between the two sets of data is that the former is more detailed and the latter more precise.

Detailed probing principles can be found on the Caida.

I'm taking the data from the Kapar tool without adding the sample.

The data together has three files, with the path data ending in. Links, with the. nodes ending with the node routing data, and the Nodes.geo ending with the geolocation data.

The detailed format can be seen in the following diagram:


Is the file for the path data. The 12th column is the number of the path. The number of a serial number router at the beginning of the next n, assuming that the IP address is followed, is its exit on the path, not that the interface data has not been detected.

So a row of data represents the path of a network layer, and each numbered router is the node on which it resides.

is a location file. Each line has the geolocation information of each detected router. Contains countries, regions. City, latitude and longitude, etc.


Is the router node data file, each line identifies the IP address of the interface on each router.


Next. for data processing. The idea is to first select the router that belongs to Vietnam from the location file.

These routers are then put into the path file to find the path that satisfies the condition. Finally, these routers and paths are written to the KML script. It can be read with Google Earth.


Wrote a screening applet, which generalizes the process, enabling the generation of a national topology script, no matter what. In order to catch the progress, the code is a bit messy ... Crossing: Don't blame it.

#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> #define MAX_LINE_SIZE512 #define MAX_CITY_NUM1200 # Define max_route_num100000 typedef struct ROUTE_INFO{//CHAR Fileinfo[10];char Route_id[10];//char Continent[5];char Country[5];//char Region[6];char city[25];float latitude;float longtitude;} route_info;typedef struct Location {float latitude;float longtitude;} Location;char City_list[max_city_num][25];int current_citynum = 0;  Route_info Routeinfo_set[max_route_num]; route_id include character ': ' int routeinfo_index = 0;  Location Location_set[max_city_num];int Location_index = 0;int get_line (int *fd, char* line_buf, int line_size) {int A, i = 0;memset (line_buf, 0, max_line_size); while (((A = GetChar ())! = ' \ n ' && a! = EOF) && i < line_size-2) markline_buf[i++] = a;line_buf[i] = ' \ n '; Add \ n to process data convinentlyif (A = =-1) return 0;elsEreturn i+1; Include \n}int Read_raw_linkfile (char *postfix) {int fd_in, fd_out, Line_size;char line_buf[max_line_size], Outfile_ Name[20];if ((fd_in = Open ("./midar-iff.links.in", o_rdonly)) = =-1) {perror ("Fail to open:"); return 0;} memset (outfile_name, 0); strcpy (Outfile_name, "link."); strcat (Outfile_name, postfix); if (fd_out = open (Outfile_name, O_RDWR | O_creat, S_IRUSR | S_IWUSR)) = =-1) {perror ("Fail to open:"); return 0;} Dup2 (fd_in, Stdin_fileno);p rintf ("Fetching%s ' link data...\n", postfix); while (line_size = Get_line (Stdin_fileno, Line_buf, Max_line_size) {if (line_buf[0] = = ' # ') continue;if (Check_link (LINE_BUF)) write (Fd_out, line_buf, Line_size) ;} Close (fd_in); close (fd_out); return 1;} void Get_location (char *line_buf) {char *ptr = Line_buf;int len = strlen (line_buf);p tr + = (len-2); while (*ptr >= 48 & amp;& *ptr <= 57) | | *ptr = = ' \ t ' | | *ptr = = '. '/*| | *ptr = = 32*/) ptr--;p tr++; MARKSSCANF (PTR, "%f%f", &location_set[location_index].latitude, &locatiOn_set[location_index].longtitude); location_index++;} void Get_routeinfo (char *line_buf) {char id_tmp[10], *ptr;memset (id_tmp, 0,) sscanf (Line_buf, "%*s%s", Routeinfo_set [routeinfo_index].route_id);/* Drop char ': ' *///for (ptr = id_tmp; *ptr! = ': '; ptr++);//memcpy (routeinfo_set[routeinfo_ index].route_id, Id_tmp, ptr-id_tmp);p tr = Line_buf;int len = strlen (line_buf);p tr + = (len-2); while (*ptr >= mp;& *ptr <= 57) | | *ptr = = ' \ t ' | | *ptr = = '. ') ptr--;p tr++; MARKSSCANF (PTR, "%f%f", &routeinfo_set[routeinfo_index].latitude, &routeinfo_set[routeinfo_index]. longtitude); routeinfo_index++;} int Read_raw_routefile (char *postfix) {int fd_in, fd_out, Fd_out_norep, Line_size;char line_buf[max_line_size], outfile _NAME[20], outfilenorep_name[20];if ((fd_in = Open ("./midar-iff.nodes.geo.in", o_rdonly)) = =-1) {perror ("Fail to open:" ); return 0;} memset (outfile_name, 0), strcpy (Outfile_name, "route."); strcat (Outfile_name, postfix); memset (outfilenorep_name, 0,); strCPY (Outfilenorep_name, "route_city."); strcat (Outfilenorep_name, postfix); if (fd_out = open (Outfile_name, O_RDWR | O_creat, S_IRUSR | S_IWUSR)) = =-1) {perror ("Fail to open:"); return 0;} if (Fd_out_norep = open (Outfilenorep_name, O_RDWR | O_creat, S_IRUSR | S_IWUSR)) = =-1) {perror ("Fail to open:"); return 0;} Dup2 (fd_in, Stdin_fileno); Route_info rinfo;while (line_size = Get_line (Stdin_fileno, Line_buf, max_line_size)) {if (line_buf[0] = = ' # ') continue; memset ((char*) &rinfo, 0, sizeof (route_info)); SSCANF (Line_buf, "%*s%s%*s%s%*s%s \t%f%f", rinfo.route_id, rinfo.co Untry, Rinfo.city, &rinfo.latitude, &rinfo.longtitude), if (!strcmp (Rinfo.country, postfix)) {if (!check_ Cityrepeatition (rinfo.city)) {write (Fd_out_norep, line_buf, line_size); Get_location (LINE_BUF);} Get_routeinfo (LINE_BUF);//strcpy (route_list[current_routenum++], rinfo.route_id); write (Fd_out, Line_buf, Line_ size);}} Close (fd_in); close (fd_out); return 1;} void Print_locationset () {int i;for (i = 0; i < Location_indeX i++) printf ("%f%f\n", Location_set[i].latitude, Location_set[i].longtitude);} void Print_routeinfoset () {int i;for (i = 0; i < Routeinfo_index; i++) printf ("%s%f%f\n", routeinfo_set[i].route_id, RO Uteinfo_set[i].latitude, routeinfo_set[i].longtitude);} /* Drop the Repeative city */int check_cityrepeatition (char *city) {int i;for (i = 0; i < Current_citynum; i++) {if (!str CMP (city, City_list[i])) return 1; strcpy (city_list[current_citynum++], city); return 0;} /* At least II adjacent route on the link */int check_link (char *line_buf) {char *ptr = line_buf, route_id[10], *tmp;int i , Pre_flag = 0;while (*ptr! = ' \ n ' && *ptr! = EOF) {memset (route_id, 0, 10*sizeof (char));p tr = STRCHR (ptr, ' n '); if (!ptr) break;tmp = Ptr;while (*tmp! = ' && *tmp! = ': ' && *tmp! = ' \ n ') tmp++;for (i = 0; (ptr + i) < tmp;          i++) Route_id[i] = * (ptr+i); Route_id[i] = ': '; Match the Formatif (Check_route (route_id)) {if (Pre_flag) return 1;else Pre_flag = 1;} else Pre_flag = 0;ptr= tmp;} return 0;} int Check_route (char *route_id) {int i;for (i = 0; i < Routeinfo_index; i++) if (!strcmp (routeinfo_set[i].route_id, rout e_id)) {return 1;} return 0;} void Draw_route (char *kmlfile_name) {int I, Fd_out;char buf[1024];if (fd_out = open (Kmlfile_name, O_RDWR | O_creat, S_IRUSR | S_IWUSR)) = =-1) {perror ("Fail to open:"); return;} printf ("Generate the Routes KML file...\n"); memset (buf, 0, 1024x768); sprintf (buf, "<document>\n<style id=\" Icon_ Style\ ">\n<IconStyle>\n<Icon>\n
The program runs with two temporary files generated, each of which is filtered out of the country's routes and links. , the data for Viet Nam are as follows:


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2ltb25feglhx3vlc3rj/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">



Finally get KML file:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2ltb25feglhx3vlc3rj/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

The last effect you see is:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2ltb25feglhx3vlc3rj/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

To optimize, differentiate the level of the link:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2ltb25feglhx3vlc3rj/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

A little excited to see the result. Bo Master can not stop, and small Japan to play a, but Japan's land scarce but the network developed, the image is too crowded is not conducive to observation. Last picture as the end of it


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Teaches you to draw the entire Vietnam backbone routing topology per minute

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.