You're dead wrong. It can - AND DOES - happen that during the time it takes to sort the list, hosts names - the underlying sort key - will be changed. I agree it's rare - and that's why I'm focused on making the sort stable. But the problem can and will occur, making it impossible to 'sort the displayed' data. Can we get it right MOST of the time - I think so, that's the change I sent Thomas last night is the first step. But always - NO.
The alternative - storing the sort key separately for the duration of the sort - has large scale memory AND performance implications. 30..40..50 characters for each of 1000s of hosts, all having to be malloc()ed and free()ed EACH TIME you prepare a report. (And that pattern is almost sure to fragment memory). A static array - then you're committing a large amount of memory to it (and Luca worked long and hard to turn the fixed memory sized hashes into linked lists, so ntop doesn't have to go through those horribly time consuming and failure prone hash resizes). You really don't understand what I'm saying - you say the IPs are in a RANDOM order. They're not. What the order is, is corrupted because of the NULL hosts in the capture you sent me. Again, the fix I sent Thomas will help here too, but can't "fix" things because the primary and secondary keys are not transitive, i.e. if primary(a) > primary(b) it does NOT follow that secondary(a) > secondary(b). However the fix will use a consistent key (either primary or secondary), and since the primary key is the number we display, things would tend to get better. The problem of sorting via nibble is conceptually simple, but actually not easy - if you change the printf()s to %03d, so the string is zero filled, it will sort, but has to be fixed back up EVERYWHERE it's displayed. Although most people don't know this, ip addresses with leading 0s are (correctly|properly|often) interpeted in OCTAL, not DECIMAL. So 037.xxxx is actually the IP address 31.xxx That means that every single usage of this field has to be tracked down and the 0s removed. It can be done, but it's not - as you all think - simple. The reality of the sort is that once most hosts are resolved, and ntop reaches a steadier state, things tend to look 'better'. If the stability fix works, this will be a more visually appealing steady state (since the occasional unresolvable host where the field stays null won't confuse the sorts). But it won't be perfect. As to why it's mostly occurring for Win32 version? Blame the vendor of the qsort() routine. In all *nix platforms, qsort is a library routine supplied as part of gcc. This tends to be the same routine in glibc across all platforms, so things tend to work the same. Whether it's RIGHT or WRONG is irrelevant, it's just that it's consistent. Win32 uses qsort.c, which is taken - according to the comments - from UCB 1993, that is the original 4.2BSD distribution - and itself credits as /* Quicksort routine from Bentley & McIlroy's "Engineering a Sort Function". */. It may well be that this routine is simply more susceptible to the problems of an unstable sort comparison function. Not surprising, since it's missing 10 years of 'tuning'. About the best I can offer is this: ignore hostSymIpAddress. if a and b both have resolved names, sort them alphabetically (return strcasecmp()). if a has a name and b does not, return -1 (a<b) if b has a name and a does not, return 1 (a>b) if both a and b have IPs, sort them as 32 or 128 bit quantities (return IPa>IPb) if a has an IP and b does not, return -1 (a<b) if b has an IP and a does not, return 1 (a>b) return MACa>MACb as a 48bit compare. This should lead to PREDICTABLE results, albeit not quite what you want. Assuming an ascending sort, you would have all dns resolved names in alphabetic, case-insensitive order all unresolved names in numerical ip order all MAC addresses -----Burton > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mark > Gibbons > Sent: Thursday, February 19, 2004 2:24 AM > To: [EMAIL PROTECTED] > Subject: RE: [Ntop] Sorting > > > Burton > > I certainly do not wish to stoke you up any more than you are > now, HOWEVER please *LISTEN* to us. > > All we want is that the DISPLAYED data is sorted - we understand > all the complex decisions that have to be made in naming the > host. The problem is that the DISPLAYED data is not sorted > correctly. My argumant is that if you can display it then you > can sort it WHATEVER you have to sort. If you have decided to > display the IP in the hosts column (for a certain host) then you > should be Alpha sorting on that - THATS IT - no more complex > argument than that. > > I actually greatly appreciate the time you have spent explaining > the naming decision. However it is IRRELAVENT to the problem of > correctly sorting the data diaplyed - or certainly should be. I > dont really mind if you show the mac, Ip or resolved host - I do > expect that the displayed data is correctly sorted. If I gave > you random words from the disctionary - random numbers from the > uk and US telephone directories some with and some without area > codes and asked you to alpha sort then you would. And I doubt > you would show the illogicality that the current sort process in > ntop does. If you are displaying the data then you should sort > by the data you are displaying - end of story. > > i.e. the ip's I gave you are in a random order - that just should > not happen. THAT IS WHAT IS APPEARING ON THE WEB PAGE AND IT > SHOULD NOT. If ntop is putting those ip's on the web page THEN > they should be sorted. This may seem unimportant to you BUT from > a users point of view I think it is > > The same is true on the data values - If you have numeric data of > some type and you are DISPLAYING that data then you should be > able to display it in a sorted order. That is Thomas's beef and > I can see on the win32 version exactly where he is coming from - > the columns are just jibberish. If you ask a column to be sorted, > by clicking on it, then you expect the column to be sorted. > > So i'm afraid sorting the data values - IS just sorting numbers. > If you are trying to make it more complex than that then that is > where the problem is. > > As I said - not trying to stoke you up - but inconsistencies like > this just hit the plain old simple user straight between the eyes > so they are important. If people see the inconsistency in a > simple sort then they wonder how innacurate the rest of the > packet capture and analysis routines are. > > Regards > > Mark > > -----Original Message----- > From: Burton M. Strauss III [mailto:[EMAIL PROTECTED] > Sent: 19 February 2004 04:42 > To: [EMAIL PROTECTED] > Subject: RE: [Ntop] Sorting > > > IT IS NOT JUST SORTING NUMBERS - PLEASE READ WHAT I WROTE THAT > EXPLAINS WHAT > IS REALLY HAPPENING. > > I CAN'T SAY IT ANY SIMPLER - it is a complex problem. You are trying to > apply simple logic to a non-simple task. > > > The sort field is one that start unvalued. As ntop learns more about the > host, it can set or change the value in that field. It > represents the best > information we have about the 'name' of that host - at that > instant in time. > > But the name of the host is not an absolute thing. At a minimum, you have > THREE names, valid in different ways. > > Your network card has an address burned into it called a MAC > address. It's > a 48 bit quantity, used for the local delivery of packets - at the lowest > (data link or frame level). > > Your Host has an address, it's a TCP/IP address - at 32 bit number that > uniquely identifies a single host on the global internet. This > is used for > non-local routing. (You might also have 128 bit IPv6 address - > either, both > or neither, but ignore this). > > Your host MAY have a name. This is used for easy of access -- > www.ntop.org > is easier than some 32 bit number. That name is mapped to the 32 > bit number > via DNS. But you don't HAVE to have a name, or you may have > multiple names > mapped to that 32 bit number, or a single name may map to multiple 32 bit > numbers... > > All THREE of these are valid names for the host, used in different ways. > > > Follow this message from me to you. > > I send it to [EMAIL PROTECTED] > > My mail program goes out to the DNS and asks for the MX (mail exchange) > record for software4you.com - and is told > > software4you.com MX (Mail Exchanger) Priority: 20 mail.de.uu.net > > So my mail program looks up mail.de.uu.net and creates a packet > to send from > MY address (67.166.222.162) to 192.76.144.89 > > That tcp/ip packet is wrapped in an Ethernet frame with the lower > level MAC > address 02:00:00:00:00:01 or whatever. > > THAT PACKET IS WHAT NTOP SEES > > (macsrc)(macdst)((ipsrc)(ipdst)...) > > The local router looks at the tcp/ip destination, decides it's > not local and > routes it as a TCP/IP packet. Each router in turn does this until finally > it gets to your local router, 149.227.16.166. > > That router looks at the addresses of it's interface and realizes > it's now a > local delivery. So it issues an ARP (Address Resolution Protocol) request > "WHO-HAS 192.76.144.89". Your mail host responds "I do, and I'm at > 02:00:00:11:11:11" - with the 48 bit address. The router rewrites the > packet to be > > (macsrc)(02:00:00:11:11:11)((ipsrc)(ipdst)...) and squirts it > onto the wire. > > The network card on the mail host recognizes it's MAC address and > grabs the > packet to process. Everyone else ignores it. > > > If you think about this, then, the 1st thing ntop usually sees is a MAC > level (48 bit) address. After a while, it sees a packet with > both that MAC > and an 32bit TCP/IP address, so it can associate the two. > > But it could be the other way around - or ntop may NEVER see the MAC > address, for example a remote host. > > After a while, ntop either sniffs a DNS packet or makes it's own query and > can then associate the TCP/IP number with the address mail.de.uu.net. > > (The reality is worse, because ntop actually deals with other kinds of > addresses - IPv6, FibreChanel host adapters, etc. - but lets leave things > where we are). > > So it comes down to a tough question - how do you sort hosts in a way that > is valid when you don't have all the information?? And what you > do know is > changing on you... > > If you sort by 48 bit mac address, 1) most people would think it's a > nonsense sort - as there is no rhyme nor reason to the 'order'. and 2) you > only know these for LOCAL addresses. > > If you sort by 32 bit IP address - regardless of whether you fix > the trivial > problem of sorting by nibbles or not - again most people would > think it's a > nonsense sort - why should www.ibm.com sort before > www.compaq.com, but after > www.abc.com??? > > If you sort by DNS resolved name, what do you do before you KNOW > this value. > It can be seconds or minutes from when you first see the host > until you know > the name. > > > The last part of the problem is that the sort key value can change in the > middle of the sort, if we happen to learn additional information. We > basically punt here - use the mutex to protect the integrity of > the data and > accept the rare, pathological case where you get a messed up sort > that will > automatically fix itself when you resort. > > > But you're still back at the crux of the problem. > > If you drop all records that don't have DNS entries, you lose data. > If you sort by any of the numeric fields, people interpret it as nonsense. > If you sort by a combination of fields, you are going to have seemingly > inexplicable results. > > > What can be done? > > Not much > > Testing BOTH the a and b parts of the hostSymIpAddress and falling back to > the backup sort if EITHER of them is \0 will slightly improve things, but > you're still going to have results that look inexplicable because of the > fall back. But at least the sort would then be stable (except in the > pathological case where the DNS resolution happens in the middle of the > sort). > > If you want to try this, change the line in reportUtils.c (around > 1099) from > this: > > if((*a)->hostSymIpAddress[0] != '\0') { > > to > > if(((*a)->hostSymIpAddress[0] != '\0') && > ((*b)->hostSymIpAddress[0] != > '\0')) { > > But that's not going to fix the whole "problem" and nothing will. We can > eliminate more and more corner cases, but we can't completely 'fix' it. > > Basically the answer is that, because ntop is a hybrid layer 2/layer 3 > analyzer, there will ALWAYS be some case you can construct where the sort > isn't going to be 'pretty'. What we have looks good in MOST cases. > Something like Rocco's change will make things a little better, but won't > fix every case. It can't. > > Live with it... > > > -----Burton > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of > > Pagel, Thomas > > Sent: Wednesday, February 18, 2004 5:38 PM > > To: [EMAIL PROTECTED] > > Subject: AW: [Ntop] Sorting > > > > > > Burton, > > > > sorry, it's past midnight here, maybe that's why I don't understand the > > logic you try to explain... But don't mind... > > > > My point is just, well, there must be a way to sort numbers > correctly... I > > will not believe that Microsoft has the only knowledge in the > world how to > > do a sorting correctly, because I never saw an incorrect sorting > > in Excel. I > > don't care about bubble or quick sort. I simply would like to see a sort > > working... Sorry, this is a simple request from a user, I can't help you > > finding out the right solution. > > > > In my former posts the answer was: tell us how to sort and we'll > > do it. It's > > not much what I would like to see. I'm not searching the > perfect sort (I'd > > like to see it but I understand that it's not easy to define), > I just want > > to have an understanding how data is sorted. This doesn't mean > that I want > > to see the code, discuss the algorithms, I'd like to have simply > > a result me > > (or better my boss) will understand without long discussions. > Is it really > > to much to ask for a numerically correct solution? > > > > I really appreciate the effort you spend to make us understand what's > > happening behind the scene. But I simply have a problem to > understand the > > point "Sorry, we simply can't sort correctly".... > > > > > > Regards, > > > > > > > > Thomas Pagel > > _______________________________________________ > Ntop mailing list > [EMAIL PROTECTED] > http://listgateway.unipi.it/mailman/listinfo/ntop > _______________________________________________ > Ntop mailing list > [EMAIL PROTECTED] > http://listgateway.unipi.it/mailman/listinfo/ntop > _______________________________________________ Ntop mailing list [EMAIL PROTECTED] http://listgateway.unipi.it/mailman/listinfo/ntop
