|
1 // Copyright (c) 2004-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 // Implements the Message sender DHCPIP6 specific access functthat fustions |
|
15 // resends messages until max retry or max count has been reached.. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file DHCPIP6MsgSender.cpp |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "DHCPServer.h" |
|
25 #include "DHCPIP6MsgSender.h" |
|
26 #include "DhcpIP6Msg.h" |
|
27 #include <in_sock.h> |
|
28 #include <es_sock.h> |
|
29 |
|
30 /* |
|
31 the retransmition alg recomended by RFC3315 (DHCPv6). Could be used for DHCPv4 as well |
|
32 for DHPCv4 doesn't specify anything |
|
33 RT for the first message transmission is based on IRT: |
|
34 |
|
35 RT = IRT + RAND*IRT |
|
36 |
|
37 RT for each subsequent message transmission is based on the previous |
|
38 value of RT: |
|
39 |
|
40 RT = 2*RTprev + RAND*RTprev |
|
41 |
|
42 MRT specifies an upper bound on the value of RT (disregarding the |
|
43 randomisation added by the use of RAND). If MRT has a value of 0, |
|
44 there is no upper limit on the value of RT. Otherwise: |
|
45 |
|
46 if (RT > MRT) |
|
47 RT = MRT + RAND*MRT |
|
48 |
|
49 */ |
|
50 TBool CDHCPIP6MessageSender::SendingContinues() const |
|
51 /** |
|
52 * determines whether to continue the sending |
|
53 * |
|
54 * |
|
55 * @internalTechnology |
|
56 * |
|
57 */ |
|
58 { |
|
59 if ( iRetryCount ) |
|
60 {//EElapsedTime option MUST be the first option in the option part of the message |
|
61 //see CDHCPIP6StateMachine::SetMessageHeader fn |
|
62 TUint32 elapsedHundrOfSecs = iMicroSecs.Int() / KMicrosecondsInSecs * 100; |
|
63 TUint8* elapsedOptionBody = const_cast<TUint8*>(iMsg->Des().Ptr()) + DHCPv6::KDHCPHeaderLength + DHCPv6::KOptionHeaderLength; |
|
64 TUint32 current = TBigEndian::GetValue( elapsedOptionBody, DHCPv6::KElapsedTimeOptionLen ); |
|
65 TBigEndian::SetValue( elapsedOptionBody, DHCPv6::KElapsedTimeOptionLen, current + elapsedHundrOfSecs ); |
|
66 } |
|
67 return iRetryCount < iMaxRetryCount && iRetryDuration < iMaxRetryDuration; |
|
68 } |
|
69 |
|
70 TBool CDHCPIP6MessageSender::CalculateDelay() |
|
71 /** |
|
72 * Calculates the first and the next retransmition time. Returns ETrue is the time calculated |
|
73 * is greater than zero. |
|
74 * |
|
75 * @internalTechnology |
|
76 * |
|
77 */ |
|
78 { |
|
79 if ( iRetryCount > -1 ) |
|
80 { |
|
81 TInt ms = iMicroSecs.Int(); |
|
82 ms = iInitialRetryTimeout ? iInitialRetryTimeout : ms + 2*ms + iXid.Rnd( -ms/10, ms/10 ); |
|
83 |
|
84 if ( ms > iMaxRetryTimeout || ms <= 0 ) |
|
85 { |
|
86 ms = iMaxRetryTimeout + iXid.Rnd( -iMaxRetryTimeout/10, iMaxRetryTimeout/10 ); |
|
87 } |
|
88 iInitialRetryTimeout = 0; |
|
89 iMicroSecs = ms; |
|
90 } |
|
91 else |
|
92 {//msg to be send for the first time |
|
93 iMicroSecs = iXid.Rnd( 0, iFirstSendDelay ); |
|
94 } |
|
95 |
|
96 return iMicroSecs.Int() > 0; |
|
97 } |
|
98 |
|
99 void CDHCPIP6MessageSender::SetListener( MMSListener* aMMSListener ) |
|
100 { |
|
101 iMMSListener = aMMSListener; |
|
102 } |
|
103 |
|
104 MMSListener* CDHCPIP6MessageSender::EventListener() const |
|
105 { |
|
106 return iMMSListener; |
|
107 } |
|
108 |
|
109 void CDHCPIP6MessageSender::SetInitialRetryTimeout( TInt aSeconds ) |
|
110 { |
|
111 iInitialRetryTimeout = KMicrosecondsInSecs * aSeconds; |
|
112 } |
|
113 |
|
114 void CDHCPIP6MessageSender::SetMaxRetryTimeout( TInt aSeconds ) |
|
115 { |
|
116 iMaxRetryTimeout = KMicrosecondsInSecs * aSeconds; |
|
117 } |
|
118 |
|
119 void CDHCPIP6MessageSender::SetMaxRetryCount( TInt aCount ) |
|
120 { |
|
121 iMaxRetryCount = aCount; |
|
122 } |
|
123 |
|
124 void CDHCPIP6MessageSender::SetMaxRetryDuration( TInt aSeconds ) |
|
125 { |
|
126 iMaxRetryDuration = KMicrosecondsInSecs * aSeconds; |
|
127 } |
|
128 |
|
129 void CDHCPIP6MessageSender::SetFirstSendDelay( TInt aSeconds ) |
|
130 { |
|
131 iFirstSendDelay = KMicrosecondsInSecs * aSeconds; |
|
132 } |