|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Contain the implementation of the class for this null agent test |
|
15 // |
|
16 // |
|
17 |
|
18 #include "NullAgentTestSteps.h" |
|
19 #include "dummynifvar.h" |
|
20 #include "in_sock.h" |
|
21 |
|
22 CTestStepNullAgtReconnect::CTestStepNullAgtReconnect(TPtrC aName) |
|
23 { |
|
24 iTestStepName=aName; |
|
25 } |
|
26 |
|
27 enum TVerdict CTestStepNullAgtReconnect::doTestStepL(void) |
|
28 { |
|
29 __UHEAP_MARK; |
|
30 |
|
31 TRequestStatus status; // status of asynchronous ops |
|
32 TInt r; // the result of various operations |
|
33 |
|
34 RSocketServ server; // connection paraphanelia |
|
35 RConnection connection; |
|
36 RSocket commandSocket, dataSocket; |
|
37 |
|
38 TInetAddr commandDest; |
|
39 commandDest.SetAddress(KDummyNifLocalAddressBase + 4); |
|
40 commandDest.SetPort(KDummyNifCmdPort); |
|
41 TInetAddr dataDest; |
|
42 dataDest.SetAddress(KDummyNifLocalAddressBase + 4); |
|
43 dataDest.SetPort(KPortNo); |
|
44 |
|
45 TBuf8<KBufferLength> buffer; |
|
46 |
|
47 /* START THE CONNECTION WE WILL USE */ |
|
48 |
|
49 r = server.Connect(); |
|
50 TESTEL(r == KErrNone, r); |
|
51 CleanupClosePushL(server); |
|
52 |
|
53 r = connection.Open(server, KAfInet); |
|
54 TESTEL(r == KErrNone, r); |
|
55 CleanupClosePushL(connection); |
|
56 |
|
57 connection.Start(status); |
|
58 User::WaitForRequest(status); |
|
59 TESTEL(status.Int() == KErrNone, status.Int()); |
|
60 |
|
61 /* OPEN 2 SOCKETS - ONE FOR COMMANDS AND ONE FOR TRAFFIC */ |
|
62 |
|
63 // to send commands to the dummy nif we need to send pseudo-traffic which |
|
64 // it will interpret as a command... hence all the socket stuff that follows |
|
65 |
|
66 // open a udp socket to send the command to the dummy nif |
|
67 r = commandSocket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
68 TESTEL(r == KErrNone, r); |
|
69 CleanupClosePushL(commandSocket); |
|
70 TESTL(commandSocket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
71 // set the source port number - otherwise will panic cos it's zero |
|
72 r = commandSocket.SetLocalPort(KDummyNifCmdPort); |
|
73 TESTEL(r == KErrNone, r); |
|
74 |
|
75 // open another socket to send data later on |
|
76 r = dataSocket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
77 TESTEL(r == KErrNone, r); |
|
78 CleanupClosePushL(dataSocket); |
|
79 TESTL(dataSocket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
80 r = dataSocket.SetLocalPort(KPortNo); |
|
81 TESTEL(r == KErrNone, r); |
|
82 |
|
83 /* SEND SOME LOOPBACK TRAFFIC */ |
|
84 |
|
85 buffer.SetMax(); |
|
86 buffer.FillZ(); |
|
87 buffer[0] = (TUint8) 0x8; // ICMP type = 8 |
|
88 buffer[1] = (TUint8) 0x0; // ICMP code = 0 |
|
89 buffer[2] = (TUint8) 0xF7; // ICMP checksum high byte |
|
90 buffer[3] = (TUint8) 0xFF; // ICMP checksum low byte |
|
91 |
|
92 dataSocket.SendTo(buffer, dataDest, 0, status); |
|
93 User::WaitForRequest(status); |
|
94 TESTEL(status.Int() == KErrNone, status.Int()); |
|
95 |
|
96 buffer.Zero(); |
|
97 dataSocket.RecvFrom(buffer, dataDest, 0, status); |
|
98 User::WaitForRequest(status); |
|
99 TESTEL(status.Int() == KErrNone, status.Int()); |
|
100 |
|
101 /* SEND THE SPECIAL COMMAND PACKET TO THE DUMMY NIF TO FORCE A RECONNECT */ |
|
102 |
|
103 buffer.SetMax(); |
|
104 buffer.FillZ(); |
|
105 buffer[0] = (TUint8) KForceReconnect; |
|
106 |
|
107 commandSocket.SendTo(buffer, commandDest, 0, status); |
|
108 User::WaitForRequest(status); |
|
109 TESTEL(status.Int() == KErrNone, status.Int()); |
|
110 |
|
111 /* WAIT A WHILE TO LET THE RECONNECT HAPPEN (OR NOT IF DIALOG APPEARS AND USER DOESN'T RESPOND!) */ |
|
112 |
|
113 User::After(10000000); |
|
114 |
|
115 /* SEND MORE LOOPBACK TRAFFIC ON THE DATA SOCKET */ |
|
116 |
|
117 // the idea is that reconnect does not lead to an erroring of the sockets - the stack should |
|
118 // not see that the rug was pulled out. |
|
119 |
|
120 buffer.SetMax(); |
|
121 buffer.FillZ(); |
|
122 buffer[0] = (TUint8) 0x8; // ICMP type = 8 |
|
123 buffer[1] = (TUint8) 0x0; // ICMP code = 0 |
|
124 buffer[2] = (TUint8) 0xF7; // ICMP checksum high byte |
|
125 buffer[3] = (TUint8) 0xFF; // ICMP checksum low byte |
|
126 |
|
127 dataSocket.SendTo(buffer, dataDest, 0, status); |
|
128 User::WaitForRequest(status); |
|
129 TESTEL(status.Int() == KErrNone, status.Int()); |
|
130 |
|
131 buffer.Zero(); |
|
132 dataSocket.RecvFrom(buffer, dataDest, 0, status); |
|
133 User::WaitForRequest(status); |
|
134 TESTEL(status.Int() == KErrNone, status.Int()); |
|
135 |
|
136 /* CLOSE EVERYTHING DOWN */ |
|
137 |
|
138 // close the data socket |
|
139 dataSocket.Shutdown(RSocket::ENormal, status); |
|
140 User::WaitForRequest(status); |
|
141 TESTEL(status.Int() == KErrNone, status.Int()); |
|
142 CleanupStack::Pop(&dataSocket); |
|
143 |
|
144 // close the command socket |
|
145 commandSocket.Shutdown(RSocket::ENormal, status); |
|
146 User::WaitForRequest(status); |
|
147 TESTEL(status.Int() == KErrNone, status.Int()); |
|
148 CleanupStack::Pop(&commandSocket); |
|
149 |
|
150 // force the destruction of the connection - if the reconnect hasn't completed yet it will be cancelled |
|
151 r = connection.Stop(); |
|
152 TESTEL(r == KErrNone, r); |
|
153 CleanupStack::Pop(&connection); |
|
154 |
|
155 // close the socket server |
|
156 server.Close(); |
|
157 CleanupStack::Pop(&server); |
|
158 |
|
159 __UHEAP_MARKEND; |
|
160 |
|
161 return iTestStepResult; |
|
162 } |