analysing network topology - more work done
[svn/Prometheus-QoS/.git] / networks.c
1 /* Modified by: xChaos, 20131029 */
2
3 #include "cll1-0.6.2.h"
4 #include "ipstruct.h"
5
6 #define STRLEN 512
7
8 extern struct IP *ips, *networks;
9
10 void update_network(char *look_for, struct IP* ip)
11 {
12 struct IP *network;
13 char *netaddr, *lastnum, *ipaddr;
14 int ipnum, netnum;
15
16 duplicate(look_for, ipaddr);
17 lastnum = strrchr(ipaddr, '.');
18 if(lastnum)
19 {
20 ipnum = atoi(lastnum + 1);
21 *lastnum = 0;
22 }
23
24 for_each(network, networks)
25 {
26 duplicate(network->addr, netaddr);
27 lastnum = strrchr(netaddr, '.');
28 if(lastnum)
29 {
30 netnum = atoi(lastnum + 1);
31 *lastnum = 0;
32 // printf("%s/%d + %d\n",network->addr,network->mask,(1<<(32-network->mask)));
33 if( eq(netaddr, ipaddr)
34 and netnum + (1<<(32-network->mask)) > ipnum
35 and netnum <= ipnum)
36 {
37 network->group += 1;
38 network->min += ip->min;
39 network->direct += ip->max<<10; /* sum of Mbps, not kbps*/
40
41 if(ip->max > network->max)
42 {
43 network->max = ip->max;
44 }
45
46 if(network->max > network->min)
47 {
48 network->desired = network->max;
49 }
50 else
51 {
52 network->desired = network->min;
53 }
54 return;
55 }
56 }
57 }
58 }
59
60 void analyse_topology(char *traceroute)
61 {
62 char *buf, *netaddr, *ptr, *lastnum, *str;
63 int col, gateway, netnum, tracert;
64 struct IP *network=NULL, *ip;
65
66 /*-----------------------------------------------------------------*/
67 puts("Analysing network topology ...");
68 /*-----------------------------------------------------------------*/
69 for_each(ip, networks)
70 {
71 printf("%s/%d %s\n",ip->addr, ip->mask, ip->name);
72 duplicate(ip->addr, buf);
73 lastnum = strrchr(buf, '.');
74 if(lastnum)
75 {
76 gateway = atoi(lastnum + 1) + 1; /* this is just common rule... */
77 *lastnum = 0;
78 string(str,STRLEN);
79 sprintf(str, traceroute, buf, gateway);
80 shell(str);
81 input(str,STRLEN)
82 {
83 if( not strstr(str, "traceroute")
84 and not strstr(str, "* * *"))
85 {
86 printf("%s",str);
87 duplicate(str, buf);
88 valid_columns(ptr, buf, ' ', col)
89 if(*ptr=='*')
90 {
91 col--;
92 }
93 else if(col==2)
94 {
95 //#ifdef DEBUG
96 printf("via [%s]\n", ptr);
97 //#endif
98 update_network(ptr, ip);
99 }
100 }
101 }
102 }
103 }
104 sort(network, networks, desc_order_by, min);
105 sort(network, networks, desc_order_by, desired);
106
107 /*-----------------------------------------------------------------*/
108 puts("Requested network parameters are:");
109 /*-----------------------------------------------------------------*/
110 for_each(ip, networks) if(ip->desired>>10 > 0)
111 {
112 printf("%s/%d %s REQUESTED=%dM (classes=%d, sum_min=%dk, max_1=%dk, sum_max=%LuM, agreg.=1:%d)\n",
113 ip->addr, ip->mask, ip->name, ip->desired>>10, ip->group, ip->min, ip->max, ip->direct,
114 (int)((float)(ip->direct)/(ip->desired>>10)));
115 }
116 exit(-1);
117 }
This page took 0.32465 seconds and 4 git commands to generate.