more network analysis
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 31 Oct 2013 14:58:46 +0000 (14:58 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 31 Oct 2013 14:58:46 +0000 (14:58 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@231 251d49ef-1d17-4917-a970-b30cf55b089b

ipstruct.h
networks.c
parsehosts.c

index ad5bf38fc7318bd80e9be31aa4dbcaff0818ac52..4f1d9aac8fbb362fceb403dc3761ea5bc9f743ef 100644 (file)
@@ -24,6 +24,7 @@ struct IP
  struct Keyword *keyword;\r
  int v6;\r
  int mask;\r
  struct Keyword *keyword;\r
  int v6;\r
  int mask;\r
+ struct IP *uplink;\r
  list(IP);\r
 };\r
 \r
  list(IP);\r
 };\r
 \r
index 3308943b68d590b010ca3d6667b4161bc7151ee7..6039ee6a48ba9bb98b603af2b2298d47f6546011 100644 (file)
@@ -5,13 +5,13 @@
 
 #define STRLEN 512
 
 
 #define STRLEN 512
 
-extern struct IP *ips, *networks;
+extern struct IP *ip, *ips, *networks;
 
 
-void update_network(char *look_for, struct IP* ip)
+struct IP *locate_network(char *look_for)
 {
  struct IP *network;
  char *netaddr, *lastnum, *ipaddr;
 {
  struct IP *network;
  char *netaddr, *lastnum, *ipaddr;
- int ipnum, netnum;
+ int ipnum, netnum, total;
 
  duplicate(look_for, ipaddr);
  lastnum = strrchr(ipaddr, '.');
 
  duplicate(look_for, ipaddr);
  lastnum = strrchr(ipaddr, '.');
@@ -25,93 +25,166 @@ void update_network(char *look_for, struct IP* ip)
  {
   duplicate(network->addr, netaddr);
   lastnum = strrchr(netaddr, '.');
  {
   duplicate(network->addr, netaddr);
   lastnum = strrchr(netaddr, '.');
-  if(lastnum)
+  if(lastnum or total)
   {
    netnum = atoi(lastnum + 1);
    *lastnum = 0;
   {
    netnum = atoi(lastnum + 1);
    *lastnum = 0;
-//   printf("%s/%d + %d\n",network->addr,network->mask,(1<<(32-network->mask)));
-   if(     eq(netaddr, ipaddr) 
-       and netnum + (1<<(32-network->mask)) > ipnum
-       and netnum <= ipnum)
+   if(    eq(netaddr, ipaddr)
+      and netnum + (1<<(32-network->mask)) > ipnum
+      and netnum <= ipnum)
    {
    {
-    network->group += 1;
-    network->min += ip->min;
-    network->direct += ip->max>>10; /* sum of Mbps, not kbps*/
+    return network;
+   }       
+  }
+ }
+ return NULL;
+}
 
 
-    if(ip->max > network->max)
-    {
-     network->max = ip->max;
-    }
 
 
-    if(network->max > network->min)
-    {
-     network->desired = network->max>>10;
-    }
-    else
-    {
-     network->desired = network->min>>10;
-    }
-    return;
-   }       
+void update_network_direct(struct IP *network, struct IP *ip)
+{
+ if(ip and network)
+ {
+  network->group += 1;
+  network->min += ip->min;
+  network->direct += ip->max>>10; /* sum of Mbps, not kbps */
+
+  if(ip->max > network->max)
+  {
+   network->max = ip->max;
+  }
+
+  if(network->max > network->min)
+  {
+   network->desired = network->max>>10;
+  }
+  else
+  {
+   network->desired = network->min>>10;
   }
  }
 }
 
   }
  }
 }
 
+
+void update_network(char *look_for, struct IP* ip)
+{
+ update_network_direct(locate_network(look_for),ip);
+}
+
+
 void analyse_topology(char *traceroute)
 {
 void analyse_topology(char *traceroute)
 {
- char *buf, *netaddr, *ptr, *lastnum, *str;
- int col, gateway, netnum, tracert;
- struct IP *network=NULL, *ip;
+ char *buf, *netaddr, *ptr, *lastnum, *str, *redundant;
+ int col, gateway, netnum, tracert, distance;
+ struct IP *network = NULL, *uplink = NULL;
+
+ string(redundant, STRLEN);
+ string(str, STRLEN); 
 
  /*-----------------------------------------------------------------*/
  puts("Analysing network topology ...");
  /*-----------------------------------------------------------------*/
 
  /*-----------------------------------------------------------------*/
  puts("Analysing network topology ...");
  /*-----------------------------------------------------------------*/
- for_each(ip, networks)
+ for_each(ip, networks) if(ip->group) /* just non-empty networks */
  { 
  { 
-  printf("%s/%d %s\n",ip->addr, ip->mask, ip->name);
+  printf("%s/%d %s ", ip->addr, ip->mask, ip->name);
   duplicate(ip->addr, buf);
   lastnum = strrchr(buf, '.');
   if(lastnum)
   {
    gateway = atoi(lastnum + 1) + 1;  /* this is just common rule... */
    *lastnum = 0;
   duplicate(ip->addr, buf);
   lastnum = strrchr(buf, '.');
   if(lastnum)
   {
    gateway = atoi(lastnum + 1) + 1;  /* this is just common rule... */
    *lastnum = 0;
-   string(str,STRLEN); 
    sprintf(str, traceroute, buf, gateway);
    shell(str);
    sprintf(str, traceroute, buf, gateway);
    shell(str);
+   *redundant = 0;
+   distance = 1;
+   uplink = NULL;
    input(str,STRLEN)
    {
    input(str,STRLEN)
    {
-    if(    not strstr(str, "traceroute")
-       and not strstr(str, "* * *"))
+    if(not strstr(str, "traceroute")) /*skip header */
     {
     {
+#ifdef DEBUG
      printf("%s",str);
      printf("%s",str);
+#endif
      duplicate(str, buf);
      valid_columns(ptr, buf, ' ', col)
      duplicate(str, buf);
      valid_columns(ptr, buf, ' ', col)
-     if(*ptr=='*')
+     if(*ptr == '*')
      {
      {
-      col--;
+      col -= 1;
      }
      }
-     else if(col==2)
+     else if(col==2 and not strstr(redundant, ptr))
      {
      {
-//#ifdef DEBUG
-      printf("via [%s]\n", ptr);
-//#endif
-      update_network(ptr, ip);
+#ifdef DEBUG
+      printf("[%s] ", ptr);
+#endif
+      network = locate_network(ptr);
+      if(network)
+      {
+       printf("[%s/%d] ", network->addr, network->mask);
+       network->mark = distance;
+       distance += 1;
+       if(uplink)
+       {
+        network->uplink = uplink;
+#ifdef DEBUG
+        printf("[%d: uplink of %s/%d is %s/%d] ",
+               network->mark, network->addr, network->mask, network->uplink->addr, network->uplink->mask);
+#endif
+       }
+       uplink = network;
+      }
+
+      if(strlen(redundant) < STRLEN - 17)
+      {
+       strcat(redundant, ptr);
+       strcat(redundant, " ");
+      }
      }
     }
      }
     }
+   }//end input loop
+
+//   ip->mark = distance;
+//   if(uplink)
+//   {
+//    ip->uplink = uplink;
+//   }
+   if(distance == 1)
+   {
+    printf("fail! \n");
+   }
+   else
+   {
+    printf("done. \n");
    }
   }
    }
   }
+ }//end for_each()
+
+ TheIP("0.0.0.0", TRUE);
+ ip->name = "TOTAL";
+ ip->mask = 0;
+
+ sort(network, networks, desc_order_by, mark); /* most distant networks first */
+ for_each(network, networks)
+ {
+  if(not network->uplink)
+  {
+   network->uplink = ip; /* global checksum */  
+  }
+  printf("(%d) uplink of %s/%d is %s/%d \n",
+         network->mark, network->addr, network->mask, network->uplink->addr, network->uplink->mask);
+  update_network_direct(network->uplink, network);
  }
  }
- sort(network, networks, desc_order_by, min);
- sort(network, networks, desc_order_by, desired);
+
+ sort(network, networks, desc_order_by, min); /* secondary ordering  */
+ sort(network, networks, desc_order_by, desired); /* primary ordering  */
 
  /*-----------------------------------------------------------------*/
 
  /*-----------------------------------------------------------------*/
- puts("Requested network parameters are:");
+ puts("\nRequested network parameters are:");
  /*-----------------------------------------------------------------*/
  for_each(ip, networks) if(ip->desired)
  {
   printf("%s/%d %s REQUESTED=%dM (classes=%d, sum_min=%dk, max_1=%dk, sum_max=%LuM, agreg.=1:%d)\n",
          ip->addr, ip->mask, ip->name, ip->desired, ip->group, ip->min, ip->max, ip->direct,
  /*-----------------------------------------------------------------*/
  for_each(ip, networks) if(ip->desired)
  {
   printf("%s/%d %s REQUESTED=%dM (classes=%d, sum_min=%dk, max_1=%dk, sum_max=%LuM, agreg.=1:%d)\n",
          ip->addr, ip->mask, ip->name, ip->desired, ip->group, ip->min, ip->max, ip->direct,
-         (int)((float)((ip->direct)/ip->desired)+.5));
+         (int)(ip->direct/(float)(ip->desired)+.5));
  }
  exit(-1);
 }
  }
  exit(-1);
 }
index bcf222e86cb8991e029841ba75bec82dd23908d0..ac9b39fd47c374f23c965bb159f3223c2648258c 100644 (file)
@@ -235,6 +235,7 @@ void parse_hosts(char *hosts)
       *ptr=0;\r
       ip->max = ip->desired = atoi(ptr+1);\r
      }\r
       *ptr=0;\r
       ip->max = ip->desired = atoi(ptr+1);\r
      }\r
+\r
      ip->min = atoi(substring);\r
      if(ip->min <= 0)\r
      {\r
      ip->min = atoi(substring);\r
      if(ip->min <= 0)\r
      {\r
@@ -242,6 +243,7 @@ void parse_hosts(char *hosts)
              str, free_min);\r
       ip->min = free_min;\r
      }\r
              str, free_min);\r
       ip->min = free_min;\r
      }\r
+\r
      if(ip->max <= ip->min)\r
      {\r
       ip->fixedprio = TRUE;\r
      if(ip->max <= ip->min)\r
      {\r
       ip->fixedprio = TRUE;\r
@@ -255,8 +257,8 @@ void parse_hosts(char *hosts)
        ip->max=ip->min;\r
       }\r
      }\r
        ip->max=ip->min;\r
       }\r
      }\r
-     ip->mark = FIRSTIPCLASS+1+class_count++;\r
 \r
 \r
+     ip->mark = FIRSTIPCLASS+1+class_count++;\r
      update_network(ip->addr, ip);\r
 \r
      if_exists(group,groups,(group->min == ip->min)) \r
      update_network(ip->addr, ip);\r
 \r
      if_exists(group,groups,(group->min == ip->min)) \r
@@ -291,4 +293,7 @@ void parse_hosts(char *hosts)
   exit(-1);\r
  }\r
  done; /* ugly macro end */\r
   exit(-1);\r
  }\r
  done; /* ugly macro end */\r
+// TheIP("0.0.0.0", TRUE);\r
+// ip->name = "TOTAL";\r
+// ip->mask = 0;\r
 }
\ No newline at end of file
 }
\ No newline at end of file
This page took 0.195361 seconds and 4 git commands to generate.