analysing network topology - more work done
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 29 Oct 2013 12:10:50 +0000 (12:10 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 29 Oct 2013 12:10:50 +0000 (12:10 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@229 251d49ef-1d17-4917-a970-b30cf55b089b

networks.c
parsehosts.c

index 965b2de339fb0fe1d7f85ca8dfd1f41c3cba18c3..c9e54f8b006b9b563e0df057bbf211628b015359 100644 (file)
@@ -7,13 +7,13 @@
 
 extern struct IP *ips, *networks;
 
-struct IP* find_network_for_ip(char *ipaddr_orig)
+void update_network(char *look_for, struct IP* ip)
 {
  struct IP *network;
  char *netaddr, *lastnum, *ipaddr;
  int ipnum, netnum;
 
- duplicate(ipaddr_orig, ipaddr);
+ duplicate(look_for, ipaddr);
  lastnum = strrchr(ipaddr, '.');
  if(lastnum)
  {
@@ -34,11 +34,27 @@ struct IP* find_network_for_ip(char *ipaddr_orig)
        and netnum + (1<<(32-network->mask)) > ipnum
        and netnum <= ipnum)
    {
-    return 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;
+    }
+    else
+    {
+     network->desired = network->min;
+    }
+    return;
    }       
   }
  }
- return NULL;
 }
 
 void analyse_topology(char *traceroute)
@@ -47,11 +63,6 @@ void analyse_topology(char *traceroute)
  int col, gateway, netnum, tracert;
  struct IP *network=NULL, *ip;
 
- for_each(ip, networks)
- {
-  printf("%s/%d %s min=%d max=%d sum=%d\n",ip->addr, ip->mask, ip->name, ip->min, ip->max, ip->desired); 
- }
-
  /*-----------------------------------------------------------------*/
  puts("Analysing network topology ...");
  /*-----------------------------------------------------------------*/
@@ -81,27 +92,26 @@ void analyse_topology(char *traceroute)
      }
      else if(col==2)
      {
+//#ifdef DEBUG
       printf("via [%s]\n", ptr);
-      network = find_network_for_ip(ptr);
-      if(network)
-      {
-       network->min += ip->min;
-       network->desired += ip->max;
-       if(ip->max > network->max)
-       {
-        network->max = ip->max;
-       }
-      }      
+//#endif
+      update_network(ptr, ip);
      }
     }
    }
   }
  }
  sort(network, networks, desc_order_by, min);
- sort(network, networks, desc_order_by, max);
- for_each(ip, networks)
+ sort(network, networks, desc_order_by, desired);
+
+ /*-----------------------------------------------------------------*/
+ puts("Requested network parameters are:");
+ /*-----------------------------------------------------------------*/
+ for_each(ip, networks) if(ip->desired>>10 > 0)
  {
-  printf("%s/%d %s min=%d max=%d sum=%d\n",ip->addr, ip->mask, ip->name, ip->min, ip->max, 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>>10, ip->group, ip->min, ip->max, ip->direct,
+         (int)((float)(ip->direct)/(ip->desired>>10)));
  }
  exit(-1);
 }
index b21af786e7d7c87a4dc0d5afb52107f08fe200a0..bcf222e86cb8991e029841ba75bec82dd23908d0 100644 (file)
@@ -17,7 +17,7 @@ extern int free_min;
 extern const int highest_priority;\r
 extern char *ip6prefix;\r
 \r
-struct IP* find_network_for_ip(char *ipaddr_orig);\r
+void update_network(char *look_for, struct IP* ip);\r
 /* implemented in networks.c */\r
 \r
 /* This must be object oriented! This looks almost like constructor ;-) */\r
@@ -257,16 +257,7 @@ void parse_hosts(char *hosts)
      }\r
      ip->mark = FIRSTIPCLASS+1+class_count++;\r
 \r
-     network = find_network_for_ip(ip->addr);\r
-     if(network)\r
-     {\r
-      network->min += ip->min;\r
-      network->desired += ip->max;\r
-      if(ip->max > network->max)\r
-      {\r
-       network->max = ip->max;\r
-      }\r
-     }\r
+     update_network(ip->addr, ip);\r
 \r
      if_exists(group,groups,(group->min == ip->min)) \r
      { \r
This page took 0.247217 seconds and 4 git commands to generate.