1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// file : Receiver.cpp
// author : Boris Kolpackov <boris@kolpackov.net>
// cvs-id : $Id$
#include "ace/OS_NS_string.h"
#include "ace/RMCast/Socket.h"
#include "Protocol.h"
#include <vector>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
typedef
std::vector<unsigned char>
Status_List;
class args {};
int
main (int argc, char* argv[])
{
try
{
if (argc < 2) throw args ();
ACE_RMCast::Address addr (argv[1]);
ACE_RMCast::Socket socket (addr);
Message expected_msg;
expected_msg.sn = 0;
for (unsigned short i = 0; i < payload_size; i++)
{
expected_msg.payload[i] = i;
}
Status_List received (message_count, 0);
Status_List damaged (message_count, 0);
Status_List duplicate (message_count, 0);
Message msg;
while (true)
{
socket.recv (&msg, sizeof (msg));
if (received[msg.sn] == 1)
{
duplicate[msg.sn] = 1;
}
else
{
received[msg.sn] = 1;
if (ACE_OS::memcmp (expected_msg.payload, msg.payload, payload_size) != 0)
{
damaged[msg.sn] = 1;
}
}
if (msg.sn + 1 == message_count) break;
}
unsigned long lost_count (0), damaged_count (0), duplicate_count (0);
for (Status_List::iterator i (received.begin ()), end (received.end ());
i != end;
++i) if (*i == 0) ++lost_count;
for (Status_List::iterator i (damaged.begin ()), end (damaged.end ());
i != end;
++i) if (*i == 1) ++damaged_count;
for (Status_List::iterator i (duplicate.begin ()), end (duplicate.end ());
i != end;
++i) if (*i == 1) ++duplicate_count;
cout << "lost : " << lost_count << endl
<< "damaged : " << damaged_count << endl
<< "duplicate : " << duplicate_count << endl << endl;
cout << "lost message dump:" << endl;
unsigned long total = 0;
for (Status_List::iterator
begin (received.begin ()), i (begin), end (received.end ());
i != end;)
{
if (*i == 0)
{
unsigned long count = 1;
for (Status_List::iterator j = i + 1;
j < end && *j == 0;
j++, count++);
cout << '\t' << i - begin << " : " << count << endl;
i += count;
total += count;
}
else ++i;
}
if (total != lost_count) cerr << "trouble" << endl;
}
catch (args const&)
{
cerr << "usage: " << argv[0] << " <IPv4 Multicast Address>" << endl;
}
}
|