INET Framework for OMNeT++/OMNEST
inet::PPP Class Reference

PPP implementation. More...

#include <PPP.h>

Inheritance diagram for inet::PPP:
inet::MACBase inet::ILifecycle

Public Member Functions

virtual ~PPP ()
 
- Public Member Functions inherited from inet::MACBase
 MACBase ()
 
virtual ~MACBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void startTransmitting (cPacket *msg)
 
virtual PPPFrameencapsulate (cPacket *msg)
 
virtual cPacket * decapsulate (PPPFrame *pppFrame)
 
virtual void refreshDisplay () const override
 
virtual void refreshOutGateConnection (bool connected)
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual InterfaceEntrycreateInterfaceEntry () override
 should create InterfaceEntry More...
 
virtual bool isUpperMsg (cMessage *msg) override
 should return true if the msg arrived from upper layer, else return false More...
 
virtual void flushQueue () override
 should clear queue and emit signal "dropPkFromHLIfaceDown" with entire packets More...
 
virtual void clearQueue () override
 should clear queue silently More...
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
- Protected Member Functions inherited from inet::MACBase
void registerInterface ()
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void updateOperationalFlag (bool isNodeUp)
 
virtual bool isNodeUp ()
 
virtual void handleMessageWhenDown (cMessage *msg)
 

Protected Attributes

long txQueueLimit = -1
 
cGate * physOutGate = nullptr
 
cChannel * datarateChannel = nullptr
 
cQueue txQueue
 
cMessage * endTransmissionEvent = nullptr
 
IPassiveQueuequeueModule = nullptr
 
TxNotifDetails notifDetails
 
std::string oldConnColor
 
long numSent = 0
 
long numRcvdOK = 0
 
long numBitErr = 0
 
long numDroppedIfaceDown = 0
 
- Protected Attributes inherited from inet::MACBase
cModule * hostModule = nullptr
 
bool isOperational = false
 
InterfaceEntryinterfaceEntry = nullptr
 

Static Protected Attributes

static simsignal_t txStateSignal = registerSignal("txState")
 
static simsignal_t rxPkOkSignal = registerSignal("rxPkOk")
 
static simsignal_t dropPkIfaceDownSignal = registerSignal("dropPkIfaceDown")
 
static simsignal_t dropPkBitErrorSignal = registerSignal("dropPkBitError")
 
static simsignal_t packetSentToLowerSignal = registerSignal("packetSentToLower")
 
static simsignal_t packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
 
static simsignal_t packetSentToUpperSignal = registerSignal("packetSentToUpper")
 
static simsignal_t packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
 

Detailed Description

PPP implementation.

Constructor & Destructor Documentation

inet::PPP::~PPP ( )
virtual
44 {
45  cancelAndDelete(endTransmissionEvent);
46 }
cMessage * endTransmissionEvent
Definition: PPP.h:45

Member Function Documentation

void inet::PPP::clearQueue ( )
overrideprotectedvirtual

should clear queue silently

Implements inet::MACBase.

388 {
389  // code would look slightly nicer with a pop() function that returns nullptr if empty
390  if (queueModule) {
391  queueModule->clear(); // clear request count
393  }
394  else {
395  txQueue.clear();
396  }
397 }
virtual void clear()=0
Clear all queued packets and stored requests.
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
cQueue txQueue
Definition: PPP.h:44
IPassiveQueue * queueModule
Definition: PPP.h:46
InterfaceEntry * inet::PPP::createInterfaceEntry ( )
overrideprotectedvirtual

should create InterfaceEntry

Implements inet::MACBase.

106 {
107  InterfaceEntry *e = new InterfaceEntry(this);
108 
109  // data rate
110  bool connected = datarateChannel != nullptr;
111  double datarate = connected ? datarateChannel->getNominalDatarate() : 0;
112  e->setDatarate(datarate);
113  e->setCarrier(connected);
114 
115  // generate a link-layer address to be used as interface token for IPv6
116  InterfaceToken token(0, getSimulation()->getUniqueNumber(), 64);
117  e->setInterfaceToken(token);
118 
119  // MTU: typical values are 576 (Internet de facto), 1500 (Ethernet-friendly),
120  // 4000 (on some point-to-point links), 4470 (Cisco routers default, FDDI compatible)
121  e->setMtu(par("mtu").longValue());
122 
123  // capabilities
124  e->setMulticast(true);
125  e->setPointToPoint(true);
126 
127  return e;
128 }
const value< double, units::C > e(1.602176487e-19)
cChannel * datarateChannel
Definition: PPP.h:42
cPacket * inet::PPP::decapsulate ( PPPFrame pppFrame)
protectedvirtual

Referenced by handleMessage().

360 {
361  cPacket *msg = pppFrame->decapsulate();
362  delete pppFrame;
363  return msg;
364 }
PPPFrame * inet::PPP::encapsulate ( cPacket *  msg)
protectedvirtual

Referenced by startTransmitting().

352 {
353  PPPFrame *pppFrame = new PPPFrame(msg->getName());
354  pppFrame->setByteLength(PPP_OVERHEAD_BYTES);
355  pppFrame->encapsulate(msg);
356  return pppFrame;
357 }
const int PPP_OVERHEAD_BYTES
Definition: PPPFrame_m.h:38
void inet::PPP::flushQueue ( )
overrideprotectedvirtual

should clear queue and emit signal "dropPkFromHLIfaceDown" with entire packets

Implements inet::MACBase.

367 {
368  // code would look slightly nicer with a pop() function that returns nullptr if empty
369  if (queueModule) {
370  while (!queueModule->isEmpty()) {
371  cMessage *msg = queueModule->pop();
372  emit(dropPkIfaceDownSignal, msg); //FIXME this signal lumps together packets from the network and packets from higher layers! separate them
373  delete msg;
374  }
375  queueModule->clear(); // clear request count
377  }
378  else {
379  while (!txQueue.isEmpty()) {
380  cMessage *msg = (cMessage *)txQueue.pop();
381  emit(dropPkIfaceDownSignal, msg); //FIXME this signal lumps together packets from the network and packets from higher layers! separate them
382  delete msg;
383  }
384  }
385 }
virtual void clear()=0
Clear all queued packets and stored requests.
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
cQueue txQueue
Definition: PPP.h:44
IPassiveQueue * queueModule
Definition: PPP.h:46
virtual bool isEmpty()=0
Return true when queue is empty, otherwise return false.
virtual cMessage * pop()=0
Returns a packet directly from the queue, bypassing the primary, send-on-request mechanism.
static simsignal_t dropPkIfaceDownSignal
Definition: PPP.h:60
void inet::PPP::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
230 {
231  if (!isOperational) {
233  return;
234  }
235 
236  if (msg == endTransmissionEvent) {
237  // Transmission finished, we can start next one.
238  EV_INFO << "Transmission successfully completed.\n";
239  emit(txStateSignal, 0L);
240 
241  // fire notification
242  notifDetails.setPacket(nullptr);
243  emit(NF_PP_TX_END, &notifDetails);
244 
245  if (!txQueue.isEmpty()) {
246  cPacket *pk = (cPacket *)txQueue.pop();
247  startTransmitting(pk);
248  }
249  else if (queueModule && 0 == queueModule->getNumPendingRequests()) {
251  }
252  }
253  else if (msg->arrivedOn("phys$i")) {
254  EV_INFO << "Received " << msg << " from network.\n";
255  //TODO: if incoming gate is not connected now, then the link has benn deleted
256  // during packet transmission --> discard incomplete packet.
257 
258  // fire notification
259  notifDetails.setPacket(PK(msg));
260  emit(NF_PP_RX_END, &notifDetails);
261 
263 
264  // check for bit errors
265  if (PK(msg)->hasBitError()) {
266  EV_WARN << "Bit error in " << msg << endl;
267  emit(dropPkBitErrorSignal, msg);
268  numBitErr++;
269  delete msg;
270  }
271  else {
272  // pass up payload
273  PPPFrame *pppFrame = check_and_cast<PPPFrame *>(msg);
274  emit(rxPkOkSignal, pppFrame);
275  cPacket *payload = decapsulate(pppFrame);
276  numRcvdOK++;
277  emit(packetSentToUpperSignal, payload);
278  EV_INFO << "Sending " << payload << " to upper layer.\n";
279  send(payload, "netwOut");
280  }
281  }
282  else { // arrived on gate "netwIn"
283  EV_INFO << "Received " << msg << " from upper layer.\n";
284  if (datarateChannel == nullptr) {
285  EV_WARN << "Interface is not connected, dropping packet " << msg << endl;
287  emit(dropPkIfaceDownSignal, msg);
288  delete msg;
289 
292  }
293  else {
295 
296  if (endTransmissionEvent->isScheduled()) {
297  // We are currently busy, so just queue up the packet.
298  EV_DETAIL << "Received " << msg << " for transmission but transmitter busy, queueing.\n";
299 
300  if (txQueueLimit && txQueue.getLength() > txQueueLimit)
301  throw cRuntimeError("txQueue length exceeds %d -- this is probably due to "
302  "a bogus app model generating excessive traffic "
303  "(or if this is normal, increase txQueueLimit!)",
304  txQueueLimit);
305 
306  txQueue.insert(msg);
307  }
308  else {
309  // We are idle, so we can start transmitting right away.
310  startTransmitting(PK(msg));
311  }
312  }
313  }
314 }
static simsignal_t packetReceivedFromUpperSignal
Definition: PPP.h:65
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
simsignal_t NF_PP_TX_END
Definition: NotifierConsts.cc:29
static simsignal_t rxPkOkSignal
Definition: PPP.h:59
cQueue txQueue
Definition: PPP.h:44
simsignal_t NF_PP_RX_END
Definition: NotifierConsts.cc:30
static simsignal_t dropPkBitErrorSignal
Definition: PPP.h:61
long numBitErr
Definition: PPP.h:55
cMessage * endTransmissionEvent
Definition: PPP.h:45
static simsignal_t packetSentToUpperSignal
Definition: PPP.h:64
TxNotifDetails notifDetails
Definition: PPP.h:48
IPassiveQueue * queueModule
Definition: PPP.h:46
static simsignal_t packetReceivedFromLowerSignal
Definition: PPP.h:63
static simsignal_t txStateSignal
Definition: PPP.h:58
bool isOperational
Definition: MACBase.h:37
virtual void handleMessageWhenDown(cMessage *msg)
Definition: MACBase.cc:108
long numRcvdOK
Definition: PPP.h:54
virtual cPacket * decapsulate(PPPFrame *pppFrame)
Definition: PPP.cc:359
long txQueueLimit
Definition: PPP.h:40
long numDroppedIfaceDown
Definition: PPP.h:56
#define PK(msg)
Definition: INETDefs.h:92
virtual void startTransmitting(cPacket *msg)
Definition: PPP.cc:205
void setPacket(cPacket *m)
Definition: TxNotifDetails.h:44
virtual int getNumPendingRequests()=0
Returns number of pending requests.
cChannel * datarateChannel
Definition: PPP.h:42
static simsignal_t dropPkIfaceDownSignal
Definition: PPP.h:60
void inet::PPP::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::MACBase.

49 {
50  MACBase::initialize(stage);
51 
52  // all initialization is done in the first stage
53  if (stage == INITSTAGE_LOCAL) {
54  txQueue.setName("txQueue");
55  endTransmissionEvent = new cMessage("pppEndTxEvent");
56 
57  txQueueLimit = par("txQueueLimit");
58 
60  WATCH(numSent);
61  WATCH(numRcvdOK);
62  WATCH(numBitErr);
63  WATCH(numDroppedIfaceDown);
64 
65  subscribe(POST_MODEL_CHANGE, this);
66 
67  emit(txStateSignal, 0L);
68 
69  // find queueModule
70  queueModule = nullptr;
71 
72  if (par("queueModule").stringValue()[0]) {
73  cModule *mod = getModuleFromPar<cModule>(par("queueModule"), this);
74  if (mod->isSimple())
75  queueModule = check_and_cast<IPassiveQueue *>(mod);
76  else {
77  cGate *queueOut = mod->gate("out")->getPathStartGate();
78  queueModule = check_and_cast<IPassiveQueue *>(queueOut->getOwnerModule());
79  }
80  }
81 
82  // remember the output gate now, to speed up send()
83  physOutGate = gate("phys$o");
84 
85  // we're connected if other end of connection path is an input gate
86  bool connected = physOutGate->getPathEndGate()->getType() == cGate::INPUT;
87  // if we're connected, get the gate with transmission rate
88  datarateChannel = connected ? physOutGate->getTransmissionChannel() : nullptr;
89  }
90  else if (stage == INITSTAGE_LINK_LAYER) {
91  // register our interface entry in IInterfaceTable
93 
94  // prepare to fire notifications
96 
97  // request first frame to send
99  EV_DETAIL << "Requesting first frame from queue module\n";
101  }
102  }
103 }
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
cQueue txQueue
Definition: PPP.h:44
void setInterfaceEntry(InterfaceEntry *e)
Definition: TxNotifDetails.h:45
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
long numBitErr
Definition: PPP.h:55
cMessage * endTransmissionEvent
Definition: PPP.h:45
virtual void initialize(int stage) override
Definition: MACBase.cc:37
TxNotifDetails notifDetails
Definition: PPP.h:48
long numSent
Definition: PPP.h:53
IPassiveQueue * queueModule
Definition: PPP.h:46
cGate * physOutGate
Definition: PPP.h:41
static simsignal_t txStateSignal
Definition: PPP.h:58
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
long numRcvdOK
Definition: PPP.h:54
long txQueueLimit
Definition: PPP.h:40
long numDroppedIfaceDown
Definition: PPP.h:56
#define stringValue()
Definition: NedFunctions.cc:24
void registerInterface()
Definition: MACBase.cc:98
virtual int getNumPendingRequests()=0
Returns number of pending requests.
cChannel * datarateChannel
Definition: PPP.h:42
virtual bool inet::PPP::isUpperMsg ( cMessage *  msg)
inlineoverrideprotectedvirtual

should return true if the msg arrived from upper layer, else return false

Implements inet::MACBase.

79 { return msg->arrivedOn("netwIn"); }
virtual int inet::PPP::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::MACBase.

87 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::PPP::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Reimplemented from inet::MACBase.

131 {
132  MACBase::receiveSignal(source, signalID, obj, details);
133 
134  if (signalID != POST_MODEL_CHANGE)
135  return;
136 
137  if (dynamic_cast<cPostPathCreateNotification *>(obj)) {
138  cPostPathCreateNotification *gcobj = (cPostPathCreateNotification *)obj;
139  if (physOutGate == gcobj->pathStartGate)
141  }
142  else if (dynamic_cast<cPostPathCutNotification *>(obj)) {
143  cPostPathCutNotification *gcobj = (cPostPathCutNotification *)obj;
144  if (physOutGate == gcobj->pathStartGate)
146  }
147  else if (datarateChannel && dynamic_cast<cPostParameterChangeNotification *>(obj)) {
148  cPostParameterChangeNotification *gcobj = (cPostParameterChangeNotification *)obj;
149  if (datarateChannel == gcobj->par->getOwner() && !strcmp("datarate", gcobj->par->getName()))
151  }
152 }
cGate * physOutGate
Definition: PPP.h:41
virtual void refreshOutGateConnection(bool connected)
Definition: PPP.cc:154
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
Definition: MACBase.cc:79
cChannel * datarateChannel
Definition: PPP.h:42
void inet::PPP::refreshDisplay ( ) const
overrideprotectedvirtual
317 {
318  std::ostringstream buf;
319  const char *color = "";
320 
321  if (datarateChannel != nullptr) {
322  char datarateText[40];
323 
324  double datarate = datarateChannel->getNominalDatarate();
325  if (datarate >= 1e9)
326  sprintf(datarateText, "%gGbps", datarate / 1e9);
327  else if (datarate >= 1e6)
328  sprintf(datarateText, "%gMbps", datarate / 1e6);
329  else if (datarate >= 1e3)
330  sprintf(datarateText, "%gkbps", datarate / 1e3);
331  else
332  sprintf(datarateText, "%gbps", datarate);
333 
334  buf << datarateText << "\nrcv:" << numRcvdOK << " snt:" << numSent;
335 
336  if (numBitErr > 0)
337  buf << "\nerr:" << numBitErr;
338 
339  if (endTransmissionEvent->isScheduled()) {
340  color = txQueue.getLength() >= 3 ? "red" : "yellow";
341  }
342  }
343  else {
344  buf << "not connected\ndropped:" << numDroppedIfaceDown;
345  color = "#707070";
346  }
347  getDisplayString().setTagArg("t", 0, buf.str().c_str());
348  getDisplayString().setTagArg("i", 1, color);
349 }
cQueue txQueue
Definition: PPP.h:44
long numBitErr
Definition: PPP.h:55
cMessage * endTransmissionEvent
Definition: PPP.h:45
long numSent
Definition: PPP.h:53
long numRcvdOK
Definition: PPP.h:54
long numDroppedIfaceDown
Definition: PPP.h:56
cChannel * datarateChannel
Definition: PPP.h:42
void inet::PPP::refreshOutGateConnection ( bool  connected)
protectedvirtual

Referenced by receiveSignal().

155 {
156  Enter_Method_Silent();
157 
158  // we're connected if other end of connection path is an input gate
159  if (connected)
160  ASSERT(physOutGate->getPathEndGate()->getType() == cGate::INPUT);
161 
162  if (!connected) {
163  if (endTransmissionEvent->isScheduled()) {
164  cancelEvent(endTransmissionEvent);
165 
166  if (datarateChannel)
167  datarateChannel->forceTransmissionFinishTime(SIMTIME_ZERO);
168  }
169 
170  if (queueModule) {
171  // Clear external queue: send a request, and received packet will be deleted in handleMessage()
174  }
175  else {
176  //Clear inner queue
177  while (!txQueue.isEmpty()) {
178  cMessage *msg = check_and_cast<cMessage *>(txQueue.pop());
179  EV_ERROR << "Interface is not connected, dropping packet " << msg << endl;
181  emit(dropPkIfaceDownSignal, msg);
182  delete msg;
183  }
184  }
185  }
186 
187  cChannel *oldChannel = datarateChannel;
188  // if we're connected, get the gate with transmission rate
189  datarateChannel = connected ? physOutGate->getTransmissionChannel() : nullptr;
190  double datarate = connected ? datarateChannel->getNominalDatarate() : 0;
191 
192  if (datarateChannel && !oldChannel)
193  datarateChannel->subscribe(POST_MODEL_CHANGE, this);
194 
195  // update interface state if it is in use
196  if (interfaceEntry) {
197  interfaceEntry->setCarrier(connected);
198  interfaceEntry->setDatarate(datarate);
199  }
200 
203 }
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
cQueue txQueue
Definition: PPP.h:44
virtual void setDatarate(double d)
Definition: InterfaceEntry.h:214
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
virtual void setCarrier(bool b)
Definition: InterfaceEntry.h:209
cMessage * endTransmissionEvent
Definition: PPP.h:45
IPassiveQueue * queueModule
Definition: PPP.h:46
cGate * physOutGate
Definition: PPP.h:41
long numDroppedIfaceDown
Definition: PPP.h:56
virtual int getNumPendingRequests()=0
Returns number of pending requests.
cChannel * datarateChannel
Definition: PPP.h:42
static simsignal_t dropPkIfaceDownSignal
Definition: PPP.h:60
void inet::PPP::startTransmitting ( cPacket *  msg)
protectedvirtual

Referenced by handleMessage().

206 {
207  // if there's any control info, remove it; then encapsulate the packet
208  delete msg->removeControlInfo();
209  PPPFrame *pppFrame = encapsulate(msg);
210 
211  // fire notification
212  notifDetails.setPacket(pppFrame);
214 
215  // send
216  EV_INFO << "Transmission of " << pppFrame << " started.\n";
217  emit(txStateSignal, 1L);
218  emit(packetSentToLowerSignal, pppFrame);
219  send(pppFrame, physOutGate);
220 
221  ASSERT(datarateChannel == physOutGate->getTransmissionChannel()); //FIXME reread datarateChannel when changed
222 
223  // schedule an event for the time when last bit will leave the gate.
224  simtime_t endTransmissionTime = datarateChannel->getTransmissionFinishTime();
225  scheduleAt(endTransmissionTime, endTransmissionEvent);
226  numSent++;
227 }
static simsignal_t packetSentToLowerSignal
Definition: PPP.h:62
cMessage * endTransmissionEvent
Definition: PPP.h:45
virtual PPPFrame * encapsulate(cPacket *msg)
Definition: PPP.cc:351
TxNotifDetails notifDetails
Definition: PPP.h:48
long numSent
Definition: PPP.h:53
cGate * physOutGate
Definition: PPP.h:41
static simsignal_t txStateSignal
Definition: PPP.h:58
void setPacket(cPacket *m)
Definition: TxNotifDetails.h:44
cChannel * datarateChannel
Definition: PPP.h:42
simsignal_t NF_PP_TX_BEGIN
Definition: NotifierConsts.cc:28

Member Data Documentation

cChannel* inet::PPP::datarateChannel = nullptr
protected
simsignal_t inet::PPP::dropPkBitErrorSignal = registerSignal("dropPkBitError")
staticprotected

Referenced by handleMessage().

simsignal_t inet::PPP::dropPkIfaceDownSignal = registerSignal("dropPkIfaceDown")
staticprotected
cMessage* inet::PPP::endTransmissionEvent = nullptr
protected
TxNotifDetails inet::PPP::notifDetails
protected
long inet::PPP::numBitErr = 0
protected
long inet::PPP::numDroppedIfaceDown = 0
protected
long inet::PPP::numRcvdOK = 0
protected
long inet::PPP::numSent = 0
protected
std::string inet::PPP::oldConnColor
protected
simsignal_t inet::PPP::packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
staticprotected

Referenced by handleMessage().

simsignal_t inet::PPP::packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
staticprotected

Referenced by handleMessage().

simsignal_t inet::PPP::packetSentToLowerSignal = registerSignal("packetSentToLower")
staticprotected

Referenced by startTransmitting().

simsignal_t inet::PPP::packetSentToUpperSignal = registerSignal("packetSentToUpper")
staticprotected

Referenced by handleMessage().

cGate* inet::PPP::physOutGate = nullptr
protected
IPassiveQueue* inet::PPP::queueModule = nullptr
protected
simsignal_t inet::PPP::rxPkOkSignal = registerSignal("rxPkOk")
staticprotected

Referenced by handleMessage().

cQueue inet::PPP::txQueue
protected
long inet::PPP::txQueueLimit = -1
protected

Referenced by handleMessage(), and initialize().

simsignal_t inet::PPP::txStateSignal = registerSignal("txState")
staticprotected

The documentation for this class was generated from the following files: