Facing problem in implementing LCP -Efficiently Coding Communications Protocols in C++

Facing problem in implementing LCP -Efficiently Coding Communications Protocols in C++

Post by aki » Wed, 11 Apr 2007 12:25:53


i To you All,

I am trying to implement LCP in c++. I am using the below article
As reference...
The actual article "Efficiently Coding Communications Protocols in C+
+"
is given at-
http://www.ddj.com/dept/cpp/193004231
I am facing some problems in understanding the article .
Can any one help me ...
I am marking in red the places I got stuck....


Implementing the Point-to-Point Protocol
Now we will look at a specific protocol, the Point-to-Point Protocol
(PPP) as defined in RFC-
1661. The Point-to-Point protocol is actually a family of protocols
sharing the same
encapsulation. A PPP implementation must include the Link Control
Protocol (LCP) and one or
more Network Control Protocols, one for each network protocol
supported. The most common
Network Control Protocol is the IP Control Protocol or IPCP. A PPP
implementation may also
include one or more authorization protocols. So the actual structure
of the PPP layer is a bit
more complex than the idealized structure shown above. The figure
below shows the structure
for the PPP protocol. It include of a single receiver and transmitter
that implement the message
encapsulation and message semantics. The LCP, each NCP and each
authorization protocol
include a context and their own state.




The State Pattern
The table shows the complexity of the protocol's behavior and coding
this state machine as C
case statements or if-else statements is a daunting task. However, the
protocol state is easily
implemented as a number of simple C++ classes using the State Pattern
described in Design
Patterns by Gamma, et al. shown below.







The LcpContext and LcpState Base Class
The class declaration for the LcpContext is show below. Note that we
have declared methods for
every event and action defined by the protocol. The LcpState class is
declared as a friend class so
that it has access to the private methods for executing actions and to
change the LcpContext's
state.
class LcpContext
{
public:
LcpContext(LcpState* initialState, PppTransmitter* transmitter);
~LcpContext();
// Events
void up();
void down();
void open();
void close();
void timeOut();
void timeOutRetryExpired();
void rcvConfigReqGood();
void rcvConfigReqBad();
void rcvConfigAck();
void rcvConfigNakRej();
void rcvTermReq();
void rcvTermAck();
void rcvUnknownCode();
void rcvCodeProtRejPermitted();
void rcvCodeProtRejCatastrophic();
void rcvEchoReq();
void rcvDiscardReq();
private:
friend class LcpState;
// Actions
void thisLayerUp();
void thisLayerDown();
void thisLayerStarted();
void thisLayerFinished();
void initRetryCount();
void zeroRetryCount();
void sendConfigReq();
void sendConfigAck();
void sendConfigNakRej();
void sendTermReq();
void sendTermAck();
void sendCodeRej();
void sendEchoReply();
void changeLcpState(LcpState* state);
LcpState* _state;
LcpTimer* _timer;
PppTransmitter* _transmitter;
};
The implementation of the event methods is simple. The event
processing is simply deferred to
the State object pointed to by _state.
void LcpContext::up()
{
_state->up(this); // why is this needed I donot understand...
}



The action methods are also simple, deferring the processing to a
transmitter or timer object.
This decouples the State objects from the PppTransmitter, PppReceiver,
and LcpTimer classes so
that the state classes can be easily used for a number of PPP
applications such as PPP over
Ethernet (P