1 /* Modified by: xChaos, 20131029 */
3 #include "cll1-0.6.2.h"
8 extern struct IP
*ip
, *ips
, *networks
;
10 struct IP
*locate_network(char *look_for
)
13 char *netaddr
, *lastnum
, *ipaddr
;
14 int ipnum
, netnum
, total
;
16 duplicate(look_for
, ipaddr
);
17 lastnum
= strrchr(ipaddr
, '.');
20 ipnum
= atoi(lastnum
+ 1);
24 for_each(network
, networks
)
26 duplicate(network
->addr
, netaddr
);
27 lastnum
= strrchr(netaddr
, '.');
30 netnum
= atoi(lastnum
+ 1);
32 if( eq(netaddr
, ipaddr
)
33 and netnum
+ (1<<(32-network
->mask
)) > ipnum
44 void update_network_direct(struct IP
*network
, struct IP
*ip
)
49 network
->min
+= ip
->min
;
50 network
->direct
+= ip
->max
>>10; /* sum of Mbps, not kbps */
52 if(ip
->max
> network
->max
)
54 network
->max
= ip
->max
;
57 if(network
->max
> network
->min
)
59 network
->desired
= network
->max
>>10;
63 network
->desired
= network
->min
>>10;
69 void update_network(char *look_for
, struct IP
* ip
)
71 update_network_direct(locate_network(look_for
),ip
);
75 void analyse_topology(char *traceroute
)
77 char *buf
, *netaddr
, *ptr
, *lastnum
, *str
, *redundant
;
78 int col
, gateway
, netnum
, tracert
, distance
;
79 struct IP
*network
= NULL
, *uplink
= NULL
;
81 string(redundant
, STRLEN
);
84 /*-----------------------------------------------------------------*/
85 puts("Analysing network topology ...");
86 /*-----------------------------------------------------------------*/
87 for_each(ip
, networks
) if(ip
->group
) /* just non-empty networks */
89 printf("%s/%d %s ", ip
->addr
, ip
->mask
, ip
->name
);
90 duplicate(ip
->addr
, buf
);
91 lastnum
= strrchr(buf
, '.');
94 gateway
= atoi(lastnum
+ 1) + 1; /* this is just common rule... */
96 sprintf(str
, traceroute
, buf
, gateway
);
103 if(not strstr(str
, "traceroute")) /*skip header */
109 valid_columns(ptr
, buf
, ' ', col
)
114 else if(col
==2 and not strstr(redundant
, ptr
))
117 printf("[%s] ", ptr
);
119 network
= locate_network(ptr
);
122 printf("[%s/%d] ", network
->addr
, network
->mask
);
123 network
->mark
= distance
;
127 network
->uplink
= uplink
;
129 printf("[%d: uplink of %s/%d is %s/%d] ",
130 network
->mark
, network
->addr
, network
->mask
, network
->uplink
->addr
, network
->uplink
->mask
);
136 if(strlen(redundant
) < STRLEN
- 17)
138 strcat(redundant
, ptr
);
139 strcat(redundant
, " ");
145 // ip->mark = distance;
148 // ip->uplink = uplink;
161 TheIP("0.0.0.0", TRUE
);
165 sort(network
, networks
, desc_order_by
, mark
); /* most distant networks first */
166 for_each(network
, networks
)
168 if(not network
->uplink
)
170 network
->uplink
= ip
; /* global checksum */
172 printf("(%d) uplink of %s/%d is %s/%d \n",
173 network
->mark
, network
->addr
, network
->mask
, network
->uplink
->addr
, network
->uplink
->mask
);
174 update_network_direct(network
->uplink
, network
);
177 sort(network
, networks
, desc_order_by
, min
); /* secondary ordering */
178 sort(network
, networks
, desc_order_by
, desired
); /* primary ordering */
180 /*-----------------------------------------------------------------*/
181 puts("\nRequested network parameters are:");
182 /*-----------------------------------------------------------------*/
183 for_each(ip
, networks
) if(ip
->desired
)
185 printf("%s/%d %s REQUESTED=%dM (classes=%d, sum_min=%dk, max_1=%dk, sum_max=%LuM, agreg.=1:%d)\n",
186 ip
->addr
, ip
->mask
, ip
->name
, ip
->desired
, ip
->group
, ip
->min
, ip
->max
, ip
->direct
,
187 (int)(ip
->direct
/(float)(ip
->desired
)+.5));
This page took 0.478389 seconds and 4 git commands to generate.