-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestClient.java
176 lines (138 loc) · 5.18 KB
/
TestClient.java
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package rdt;
public class TestClient
{
public TestClient() {
}
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("Required arguments: dst_hostname dst_port local_port");
return;
}
String hostname = args[0];
int dst_port = Integer.parseInt(args[1]);
int local_port = Integer.parseInt(args[2]);
RDT rdt = null;
int dataSize;
// byte[] buf = new byte[RDT.MSS];
byte[] data;
// choose a test case
int testCase = 7;
switch ( testCase )
{
case 1:
// send a long 45 byte message
// sndBufSize = rcvBufSize = 1
// 0 loss rate
RDT.setLossRate( 0.0 );
dataSize = 45;
rdt = new RDT( hostname, dst_port, local_port, 1, 1, RDT.GBN );
data = new byte[dataSize];
for ( int i = 0; i < 10; i++ ) { data[i] = 7; }
for ( int i = 10; i < 20; i++ ) { data[i] = 6; }
for ( int i = 20; i < 30; i++ ) { data[i] = 5; }
for ( int i = 30; i < 40; i++ ) { data[i] = 4; }
for ( int i = 40; i < dataSize; i++ ) { data[i] = 3; }
rdt.send( data, dataSize );
break;
case 2: // GBN with small message and 0 loss rate
// send a small 10 byte message
// sndBufSize = rcvBufSize = 10
// 0 loss rate
dataSize = 10;
RDT.setLossRate( 0.0 );
rdt = new RDT( hostname, dst_port, local_port, 10, 10, RDT.GBN );
data = new byte[dataSize];
for (int i = 0; i < dataSize; i++) { data[i] = 9; }
rdt.send( data, dataSize );
break;
case 3: // GBN with long message and 0 loss rate
// send a long 45 byte message
// sndBufSize = rcvBufSize = 3
// 0 loss rate
RDT.setLossRate( 0.0 );
dataSize = 45;
rdt = new RDT( hostname, dst_port, local_port, 3, 3, RDT.GBN );
data = new byte[dataSize];
for ( int i = 0; i < 10; i++ ) { data[i] = 7; }
for ( int i = 10; i < 20; i++ ) { data[i] = 6; }
for ( int i = 20; i < 30; i++ ) { data[i] = 5; }
for ( int i = 30; i < 40; i++ ) { data[i] = 4; }
for ( int i = 40; i < dataSize; i++ ) { data[i] = 3; }
rdt.send( data, dataSize );
break;
case 4: // GBN with one-way losses
// send 5 small back to back messages
// 40% loss rate
dataSize = 10;
rdt = new RDT( hostname, dst_port, local_port, 10, 10, RDT.GBN );
data = new byte[dataSize];
RDT.setLossRate( 0.4 );
for ( byte j = 9; j >= 5; j-- )
{
for ( int i = 0; i < dataSize; i++ ) { data[i] = j; }
rdt.send( data, dataSize );
}
break;
case 5: // GBN with two-way losses
// send 5 small back to back messages
// 80% loss rate
dataSize = 10;
rdt = new RDT( hostname, dst_port, local_port, 1, 1, RDT.GBN );
data = new byte[dataSize];
RDT.setLossRate( 0.8 );
for ( byte j = 9; j >= 8; j-- )
{
for ( int i = 0; i < dataSize; i++ ) { data[i] = j; }
rdt.send( data, dataSize );
}
break;
case 6: // Selective Repeat with 0 loss rate
// send 0 loss rate
dataSize = 10;
rdt = new RDT( hostname, dst_port, local_port, 10, 10, RDT.SR );
data = new byte[dataSize];
RDT.setLossRate( 0.0 );
for ( byte j = 9; j >= 4; j-- )
{
for ( int i = 0; i < dataSize; i++ ) { data[i] = j; }
rdt.send( data, dataSize );
}
break;
case 7:
// case 7 : Selective Repeat with two-way losses
// 40% loss rate
dataSize = 45;
RDT.setLossRate( 0.4 );
rdt = new RDT( hostname, dst_port, local_port, 6, 6, RDT.SR );
data = new byte[dataSize];
for ( byte j = 9; j >= 0; j-- )
{
for ( int i = 0; i < dataSize; i++ ) { data[i] = j; }
rdt.send( data, dataSize );
}
break;
case 8:
// case 8 : Selective Repeat + flow control with two-way losses
// 40% loss rate
dataSize = 45;
RDT.setLossRate( 0.4 );
rdt = new RDT( hostname, dst_port, local_port, 6, 6, RDT.SR_FC );
data = new byte[dataSize];
for ( byte j = 9; j >= 0; j-- )
{
for ( int i = 0; i < dataSize; i++ ) { data[i] = j; }
rdt.send( data, dataSize );
}
break;
}
// System.out.println(System.currentTimeMillis() + ":Client has sent all data " );
// System.out.flush();
// System.out.println("Client has called rdt.receive");
// rdt.receive(buf, RDT.MSS);
// rdt.close();
System.out.println("Client is done " );
}
}