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

This class implements the Greedy Perimeter Stateless Routing for Wireless Networks. More...

#include <GPSR.h>

Inheritance diagram for inet::GPSR:
inet::ILifecycle inet::INetfilter::IHook

Public Member Functions

 GPSR ()
 
virtual ~GPSR ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::INetfilter::IHook
virtual ~IHook ()
 

Protected Member Functions

virtual int numInitStages () const override
 
void initialize (int stage) override
 
void handleMessage (cMessage *message) override
 

Private Member Functions

void processSelfMessage (cMessage *message)
 
void processMessage (cMessage *message)
 
void scheduleBeaconTimer ()
 
void processBeaconTimer ()
 
void schedulePurgeNeighborsTimer ()
 
void processPurgeNeighborsTimer ()
 
void sendUDPPacket (UDPPacket *packet, double delay)
 
void processUDPPacket (UDPPacket *packet)
 
GPSRBeaconcreateBeacon ()
 
void sendBeacon (GPSRBeacon *beacon, double delay)
 
void processBeacon (GPSRBeacon *beacon)
 
GPSROptioncreateGpsrOption (L3Address destination, cPacket *content)
 
int computeOptionLength (GPSROption *gpsrOption)
 
void setGpsrOptionOnNetworkDatagram (INetworkDatagram *datagram)
 
void removeGpsrOptionFromNetworkDatagram (INetworkDatagram *datagram)
 
GPSROptionfindGpsrOptionInNetworkDatagram (INetworkDatagram *datagram)
 
const GPSROptionfindGpsrOptionInNetworkDatagram (INetworkDatagram *datagram) const
 
GPSROptiongetGpsrOptionFromNetworkDatagram (INetworkDatagram *datagram)
 
const GPSROptiongetGpsrOptionFromNetworkDatagram (INetworkDatagram *datagram) const
 
bool isNodeUp () const
 
void configureInterfaces ()
 
Coord getDestinationPosition (const L3Address &address) const
 
Coord getNeighborPosition (const L3Address &address) const
 
double getDestinationAngle (const L3Address &address)
 
double getNeighborAngle (const L3Address &address)
 
std::string getHostName () const
 
L3Address getSelfAddress () const
 
L3Address getSenderNeighborAddress (INetworkDatagram *datagram) const
 
simtime_t getNextNeighborExpiration ()
 
void purgeNeighbors ()
 
std::vector< L3AddressgetPlanarNeighbors ()
 
L3Address getNextPlanarNeighborCounterClockwise (const L3Address &startNeighborAddress, double startNeighborAngle)
 
L3Address findNextHop (INetworkDatagram *datagram, const L3Address &destination)
 
L3Address findGreedyRoutingNextHop (INetworkDatagram *datagram, const L3Address &destination)
 
L3Address findPerimeterRoutingNextHop (INetworkDatagram *datagram, const L3Address &destination)
 
Result routeDatagram (INetworkDatagram *datagram, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop)
 
virtual Result datagramPreRoutingHook (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the lower layer. More...
 
virtual Result datagramForwardHook (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop) override
 This is the second hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual Result datagramPostRoutingHook (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop) override
 This is the last hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual Result datagramLocalInHook (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry) override
 This is the last hook called by the network protocol before it sends a datagram to the upper layer. More...
 
virtual Result datagramLocalOutHook (INetworkDatagram *datagram, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the upper layer. More...
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 

Static Private Member Functions

static Coord intersectSections (Coord &begin1, Coord &end1, Coord &begin2, Coord &end2)
 
static double getVectorAngle (Coord vector)
 

Private Attributes

GPSRPlanarizationMode planarizationMode = (GPSRPlanarizationMode)-1
 
const char * interfaces = nullptr
 
simtime_t beaconInterval
 
simtime_t maxJitter
 
simtime_t neighborValidityInterval
 
cModule * host = nullptr
 
NodeStatusnodeStatus = nullptr
 
IMobilitymobility = nullptr
 
IL3AddressTypeaddressType = nullptr
 
IInterfaceTableinterfaceTable = nullptr
 
const char * outputInterface = nullptr
 
IRoutingTableroutingTable = nullptr
 
INetfilternetworkProtocol = nullptr
 
int positionByteLength = -1
 
cMessage * beaconTimer = nullptr
 
cMessage * purgeNeighborsTimer = nullptr
 
PositionTable neighborPositionTable
 

Static Private Attributes

static PositionTable globalPositionTable
 

Additional Inherited Members

- Public Types inherited from inet::INetfilter::IHook
enum  Type {
  PREROUTING, LOCALIN, FORWARD, POSTROUTING,
  LOCALOUT
}
 
enum  Result { ACCEPT, DROP, QUEUE, STOLEN }
 

Detailed Description

This class implements the Greedy Perimeter Stateless Routing for Wireless Networks.

The implementation supports both GG and RNG planarization algorithms.

For more information on the routing algorithm, see the GPSR paper http://www.eecs.harvard.edu/~htk/publication/2000-mobi-karp-kung.pdf

Constructor & Destructor Documentation

inet::GPSR::GPSR ( )
54 {
55 }
inet::GPSR::~GPSR ( )
virtual
58 {
59  cancelAndDelete(beaconTimer);
60  cancelAndDelete(purgeNeighborsTimer);
61 }
cMessage * beaconTimer
Definition: GPSR.h:73
cMessage * purgeNeighborsTimer
Definition: GPSR.h:74

Member Function Documentation

int inet::GPSR::computeOptionLength ( GPSROption gpsrOption)
private

Referenced by createGpsrOption().

267 {
268  // routingMode
269  int routingModeBytes = 1;
270  // destinationPosition, perimeterRoutingStartPosition, perimeterRoutingForwardPosition
271  int positionsBytes = 3 * positionByteLength;
272  // currentFaceFirstSenderAddress, currentFaceFirstReceiverAddress, senderAddress
273  int addressesBytes = 3 * getSelfAddress().getAddressType()->getAddressByteLength();
274  // type and length
275  int tlBytes = 1 + 1;
276 
277  return tlBytes + routingModeBytes + positionsBytes + addressesBytes;
278 }
int positionByteLength
Definition: GPSR.h:70
IL3AddressType * getAddressType() const
Definition: L3Address.cc:60
L3Address getSelfAddress() const
Definition: GPSR.cc:367
int getAddressByteLength() const
Definition: IL3AddressType.h:36
void inet::GPSR::configureInterfaces ( )
private

Referenced by handleOperationStage(), and initialize().

290 {
291  // join multicast groups
292  cPatternMatcher interfaceMatcher(interfaces, false, true, false);
293  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++) {
294  InterfaceEntry *interfaceEntry = interfaceTable->getInterface(i);
295  if (interfaceEntry->isMulticast() && interfaceMatcher.matches(interfaceEntry->getName()))
297  }
298 }
virtual void joinMulticastGroup(const L3Address &address) const
Definition: InterfaceEntry.cc:330
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
IInterfaceTable * interfaceTable
Definition: GPSR.h:63
IL3AddressType * addressType
Definition: GPSR.h:62
const char * interfaces
Definition: GPSR.h:53
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
virtual L3Address getLinkLocalManetRoutersMulticastAddress() const =0
GPSRBeacon * inet::GPSR::createBeacon ( )
private

Referenced by processBeaconTimer().

221 {
222  GPSRBeacon *beacon = new GPSRBeacon("GPSRBeacon");
223  beacon->setAddress(getSelfAddress());
224  beacon->setPosition(mobility->getCurrentPosition());
225  beacon->setByteLength(getSelfAddress().getAddressType()->getAddressByteLength() + positionByteLength);
226  return beacon;
227 }
int positionByteLength
Definition: GPSR.h:70
IMobility * mobility
Definition: GPSR.h:61
L3Address getSelfAddress() const
Definition: GPSR.cc:367
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
GPSROption * inet::GPSR::createGpsrOption ( L3Address  destination,
cPacket *  content 
)
private

Referenced by setGpsrOptionOnNetworkDatagram().

257 {
258  GPSROption *gpsrOption = new GPSROption();
259  gpsrOption->setRoutingMode(GPSR_GREEDY_ROUTING);
260  // KLUDGE: implement position registry protocol
261  gpsrOption->setDestinationPosition(getDestinationPosition(destination));
262  gpsrOption->setLength(computeOptionLength(gpsrOption));
263  return gpsrOption;
264 }
int computeOptionLength(GPSROption *gpsrOption)
Definition: GPSR.cc:266
Coord getDestinationPosition(const L3Address &address) const
Definition: GPSR.cc:325
Definition: GPSRDefs.h:28
virtual Result inet::GPSR::datagramForwardHook ( INetworkDatagram datagram,
const InterfaceEntry inputInterfaceEntry,
const InterfaceEntry *&  outputInterfaceEntry,
L3Address nextHopAddress 
)
inlineoverrideprivatevirtual

This is the second hook called by the network protocol before it sends a datagram to the lower layer.

This is done after the datagramPreRoutingHook or the datagramLocalInHook is called and the datagram is routed.

Implements inet::INetfilter::IHook.

158 { return ACCEPT; }
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
virtual Result inet::GPSR::datagramLocalInHook ( INetworkDatagram datagram,
const InterfaceEntry inputInterfaceEntry 
)
inlineoverrideprivatevirtual

This is the last hook called by the network protocol before it sends a datagram to the upper layer.

This is done after the datagramPreRoutingHook is called and the datagram is routed.

Implements inet::INetfilter::IHook.

160 { return ACCEPT; }
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
INetfilter::IHook::Result inet::GPSR::datagramLocalOutHook ( INetworkDatagram datagram,
const InterfaceEntry *&  outputInterfaceEntry,
L3Address nextHopAddress 
)
overrideprivatevirtual

This is the first hook called by the network protocol before it routes a datagram that was received from the upper layer.

The nextHopAddress is ignored when the outputInterfaceEntry is a nullptr. After this is done

Implements inet::INetfilter::IHook.

704 {
705  Enter_Method("datagramLocalOutHook");
706  const L3Address& destination = datagram->getDestinationAddress();
707  if (destination.isMulticast() || destination.isBroadcast() || routingTable->isLocalAddress(destination))
708  return ACCEPT;
709  else {
711  return routeDatagram(datagram, outputInterfaceEntry, nextHop);
712  }
713 }
void setGpsrOptionOnNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:592
virtual bool isLocalAddress(const L3Address &dest) const =0
Checks if the address is a local one, i.e.
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
IRoutingTable * routingTable
Definition: GPSR.h:65
Result routeDatagram(INetworkDatagram *datagram, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop)
Definition: GPSR.cc:572
virtual Result inet::GPSR::datagramPostRoutingHook ( INetworkDatagram datagram,
const InterfaceEntry inputInterfaceEntry,
const InterfaceEntry *&  outputInterfaceEntry,
L3Address nextHopAddress 
)
inlineoverrideprivatevirtual

This is the last hook called by the network protocol before it sends a datagram to the lower layer.

Implements inet::INetfilter::IHook.

159 { return ACCEPT; }
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
INetfilter::IHook::Result inet::GPSR::datagramPreRoutingHook ( INetworkDatagram datagram,
const InterfaceEntry inputInterfaceEntry,
const InterfaceEntry *&  outputInterfaceEntry,
L3Address nextHopAddress 
)
overrideprivatevirtual

This is the first hook called by the network protocol before it routes a datagram that was received from the lower layer.

The nextHopAddress is ignored when the outputInterfaceEntry is nullptr.

Implements inet::INetfilter::IHook.

694 {
695  Enter_Method("datagramPreRoutingHook");
696  const L3Address& destination = datagram->getDestinationAddress();
697  if (destination.isMulticast() || destination.isBroadcast() || routingTable->isLocalAddress(destination))
698  return ACCEPT;
699  else
700  return routeDatagram(datagram, outputInterfaceEntry, nextHop);
701 }
virtual bool isLocalAddress(const L3Address &dest) const =0
Checks if the address is a local one, i.e.
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
IRoutingTable * routingTable
Definition: GPSR.h:65
Result routeDatagram(INetworkDatagram *datagram, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHop)
Definition: GPSR.cc:572
GPSROption * inet::GPSR::findGpsrOptionInNetworkDatagram ( INetworkDatagram datagram)
private

Referenced by getGpsrOptionFromNetworkDatagram().

644 {
645  cPacket *networkPacket = check_and_cast<cPacket *>(datagram);
646  GPSROption *gpsrOption = nullptr;
647 
648 #ifdef WITH_IPv4
649  if (dynamic_cast<IPv4Datagram *>(networkPacket)) {
650  IPv4Datagram *dgram = static_cast<IPv4Datagram *>(networkPacket);
651  gpsrOption = check_and_cast_nullable<GPSROption *>(dgram->findOptionByType(IPOPTION_TLV_GPSR));
652  }
653  else
654 #endif
655 #ifdef WITH_IPv6
656  if (dynamic_cast<IPv6Datagram *>(networkPacket)) {
657  IPv6Datagram *dgram = static_cast<IPv6Datagram *>(networkPacket);
658  IPv6HopByHopOptionsHeader *hdr = check_and_cast_nullable<IPv6HopByHopOptionsHeader *>(dgram->findExtensionHeaderByType(IP_PROT_IPv6EXT_HOP));
659  if (hdr != nullptr) {
660  int i = (hdr->getTlvOptions().findByType(IPv6TLVOPTION_TLV_GPSR));
661  if (i >= 0)
662  gpsrOption = check_and_cast_nullable<GPSROption *>(&(hdr->getTlvOptions().at(i)));
663  }
664  }
665  else
666 #endif
667 #ifdef WITH_GENERIC
668  if (dynamic_cast<GenericDatagram *>(networkPacket)) {
669  GenericDatagram *dgram = static_cast<GenericDatagram *>(networkPacket);
670  int i = (dgram->getTlvOptions().findByType(GENERIC_TLVOPTION_TLV_GPSR));
671  if (i >= 0)
672  gpsrOption = check_and_cast_nullable<GPSROption *>(&(dgram->getTlvOptions().at(i)));
673  }
674  else
675 #endif
676  {
677  }
678  return gpsrOption;
679 }
Definition: IPv6ExtensionHeaders_m.h:60
Definition: GenericDatagram_m.h:57
Definition: IPProtocolId_m.h:94
Definition: IPv4Datagram_m.h:114
const GPSROption* inet::GPSR::findGpsrOptionInNetworkDatagram ( INetworkDatagram datagram) const
inlineprivate

Referenced by findGpsrOptionInNetworkDatagram().

117 { return const_cast<GPSR *>(this)->findGpsrOptionInNetworkDatagram(datagram); }
GPSROption * findGpsrOptionInNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:643
GPSR()
Definition: GPSR.cc:53
L3Address inet::GPSR::findGreedyRoutingNextHop ( INetworkDatagram datagram,
const L3Address destination 
)
private

Referenced by findNextHop(), and findPerimeterRoutingNextHop().

488 {
489  EV_DEBUG << "Finding next hop using greedy routing: destination = " << destination << endl;
490  GPSROption *gpsrOption = getGpsrOptionFromNetworkDatagram(datagram);
491  L3Address selfAddress = getSelfAddress();
492  Coord selfPosition = mobility->getCurrentPosition();
493  Coord destinationPosition = gpsrOption->getDestinationPosition();
494  double bestDistance = (destinationPosition - selfPosition).length();
495  L3Address bestNeighbor;
496  std::vector<L3Address> neighborAddresses = neighborPositionTable.getAddresses();
497  for (auto& neighborAddress: neighborAddresses) {
498  Coord neighborPosition = neighborPositionTable.getPosition(neighborAddress);
499  double neighborDistance = (destinationPosition - neighborPosition).length();
500  if (neighborDistance < bestDistance) {
501  bestDistance = neighborDistance;
502  bestNeighbor = neighborAddress;
503  }
504  }
505  if (bestNeighbor.isUnspecified()) {
506  EV_DEBUG << "Switching to perimeter routing: destination = " << destination << endl;
507  gpsrOption->setRoutingMode(GPSR_PERIMETER_ROUTING);
508  gpsrOption->setPerimeterRoutingStartPosition(selfPosition);
509  gpsrOption->setCurrentFaceFirstSenderAddress(selfAddress);
510  gpsrOption->setCurrentFaceFirstReceiverAddress(L3Address());
511  return findPerimeterRoutingNextHop(datagram, destination);
512  }
513  else
514  return bestNeighbor;
515 }
Coord getPosition(const L3Address &address) const
Definition: PositionTable.cc:38
std::vector< L3Address > getAddresses() const
Definition: PositionTable.cc:24
Definition: GPSRDefs.h:29
PositionTable neighborPositionTable
Definition: GPSR.h:75
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
IMobility * mobility
Definition: GPSR.h:61
L3Address getSelfAddress() const
Definition: GPSR.cc:367
L3Address findPerimeterRoutingNextHop(INetworkDatagram *datagram, const L3Address &destination)
Definition: GPSR.cc:517
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
L3Address inet::GPSR::findNextHop ( INetworkDatagram datagram,
const L3Address destination 
)
private

Referenced by routeDatagram().

478 {
479  GPSROption *gpsrOption = getGpsrOptionFromNetworkDatagram(datagram);
480  switch (gpsrOption->getRoutingMode()) {
481  case GPSR_GREEDY_ROUTING: return findGreedyRoutingNextHop(datagram, destination);
482  case GPSR_PERIMETER_ROUTING: return findPerimeterRoutingNextHop(datagram, destination);
483  default: throw cRuntimeError("Unknown routing mode");
484  }
485 }
L3Address findGreedyRoutingNextHop(INetworkDatagram *datagram, const L3Address &destination)
Definition: GPSR.cc:487
Definition: GPSRDefs.h:29
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
L3Address findPerimeterRoutingNextHop(INetworkDatagram *datagram, const L3Address &destination)
Definition: GPSR.cc:517
Definition: GPSRDefs.h:28
L3Address inet::GPSR::findPerimeterRoutingNextHop ( INetworkDatagram datagram,
const L3Address destination 
)
private

Referenced by findGreedyRoutingNextHop(), and findNextHop().

518 {
519  EV_DEBUG << "Finding next hop using perimeter routing: destination = " << destination << endl;
520  GPSROption *gpsrOption = getGpsrOptionFromNetworkDatagram(datagram);
521  L3Address selfAddress = getSelfAddress();
522  Coord selfPosition = mobility->getCurrentPosition();
523  Coord perimeterRoutingStartPosition = gpsrOption->getPerimeterRoutingStartPosition();
524  Coord destinationPosition = gpsrOption->getDestinationPosition();
525  double selfDistance = (destinationPosition - selfPosition).length();
526  double perimeterRoutingStartDistance = (destinationPosition - perimeterRoutingStartPosition).length();
527  if (selfDistance < perimeterRoutingStartDistance) {
528  EV_DEBUG << "Switching to greedy routing: destination = " << destination << endl;
529  gpsrOption->setRoutingMode(GPSR_GREEDY_ROUTING);
530  gpsrOption->setPerimeterRoutingStartPosition(Coord());
531  gpsrOption->setPerimeterRoutingForwardPosition(Coord());
532  return findGreedyRoutingNextHop(datagram, destination);
533  }
534  else {
535  L3Address& firstSenderAddress = gpsrOption->getCurrentFaceFirstSenderAddress();
536  L3Address& firstReceiverAddress = gpsrOption->getCurrentFaceFirstReceiverAddress();
537  L3Address nextNeighborAddress = getSenderNeighborAddress(datagram);
538  bool hasIntersection;
539  do {
540  if (nextNeighborAddress.isUnspecified())
541  nextNeighborAddress = getNextPlanarNeighborCounterClockwise(nextNeighborAddress, getDestinationAngle(destination));
542  else
543  nextNeighborAddress = getNextPlanarNeighborCounterClockwise(nextNeighborAddress, getNeighborAngle(nextNeighborAddress));
544  if (nextNeighborAddress.isUnspecified())
545  break;
546  EV_DEBUG << "Intersecting towards next hop: nextNeighbor = " << nextNeighborAddress << ", firstSender = " << firstSenderAddress << ", firstReceiver = " << firstReceiverAddress << ", destination = " << destination << endl;
547  Coord nextNeighborPosition = getNeighborPosition(nextNeighborAddress);
548  Coord intersection = intersectSections(perimeterRoutingStartPosition, destinationPosition, selfPosition, nextNeighborPosition);
549  hasIntersection = !std::isnan(intersection.x);
550  if (hasIntersection) {
551  EV_DEBUG << "Edge to next hop intersects: intersection = " << intersection << ", nextNeighbor = " << nextNeighborAddress << ", firstSender = " << firstSenderAddress << ", firstReceiver = " << firstReceiverAddress << ", destination = " << destination << endl;
552  gpsrOption->setCurrentFaceFirstSenderAddress(selfAddress);
553  gpsrOption->setCurrentFaceFirstReceiverAddress(L3Address());
554  }
555  } while (hasIntersection);
556  if (firstSenderAddress == selfAddress && firstReceiverAddress == nextNeighborAddress) {
557  EV_DEBUG << "End of perimeter reached: firstSender = " << firstSenderAddress << ", firstReceiver = " << firstReceiverAddress << ", destination = " << destination << endl;
558  return L3Address();
559  }
560  else {
561  if (gpsrOption->getCurrentFaceFirstReceiverAddress().isUnspecified())
562  gpsrOption->setCurrentFaceFirstReceiverAddress(nextNeighborAddress);
563  return nextNeighborAddress;
564  }
565  }
566 }
L3Address findGreedyRoutingNextHop(INetworkDatagram *datagram, const L3Address &destination)
Definition: GPSR.cc:487
double getNeighborAngle(const L3Address &address)
Definition: GPSR.cc:353
static Coord intersectSections(Coord &begin1, Coord &end1, Coord &begin2, Coord &end2)
Definition: GPSR.cc:304
Coord getNeighborPosition(const L3Address &address) const
Definition: GPSR.cc:331
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
double getDestinationAngle(const L3Address &address)
Definition: GPSR.cc:348
IMobility * mobility
Definition: GPSR.h:61
L3Address getNextPlanarNeighborCounterClockwise(const L3Address &startNeighborAddress, double startNeighborAngle)
Definition: GPSR.cc:453
L3Address getSelfAddress() const
Definition: GPSR.cc:367
L3Address getSenderNeighborAddress(INetworkDatagram *datagram) const
Definition: GPSR.cc:385
Definition: GPSRDefs.h:28
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
double inet::GPSR::getDestinationAngle ( const L3Address address)
private

Referenced by findPerimeterRoutingNextHop().

349 {
351 }
static double getVectorAngle(Coord vector)
Definition: GPSR.cc:340
Coord getDestinationPosition(const L3Address &address) const
Definition: GPSR.cc:325
IMobility * mobility
Definition: GPSR.h:61
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
Coord inet::GPSR::getDestinationPosition ( const L3Address address) const
private

Referenced by createGpsrOption(), and getDestinationAngle().

326 {
327  // KLUDGE: implement position registry protocol
328  return globalPositionTable.getPosition(address);
329 }
Coord getPosition(const L3Address &address) const
Definition: PositionTable.cc:38
static PositionTable globalPositionTable
Definition: GPSR.h:67
GPSROption * inet::GPSR::getGpsrOptionFromNetworkDatagram ( INetworkDatagram datagram)
private

Referenced by findGreedyRoutingNextHop(), findNextHop(), findPerimeterRoutingNextHop(), getSenderNeighborAddress(), and routeDatagram().

682 {
683  GPSROption *gpsrOption = findGpsrOptionInNetworkDatagram(datagram);
684  if (gpsrOption == nullptr)
685  throw cRuntimeError("GPSR option not found in datagram!");
686  return gpsrOption;
687 }
GPSROption * findGpsrOptionInNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:643
const GPSROption* inet::GPSR::getGpsrOptionFromNetworkDatagram ( INetworkDatagram datagram) const
inlineprivate

Referenced by getGpsrOptionFromNetworkDatagram().

121 { return const_cast<GPSR *>(this)->getGpsrOptionFromNetworkDatagram(datagram); }
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
GPSR()
Definition: GPSR.cc:53
std::string inet::GPSR::getHostName ( ) const
private
363 {
364  return host->getFullName();
365 }
cModule * host
Definition: GPSR.h:59
double inet::GPSR::getNeighborAngle ( const L3Address address)
private

Referenced by findPerimeterRoutingNextHop(), and getNextPlanarNeighborCounterClockwise().

354 {
356 }
static double getVectorAngle(Coord vector)
Definition: GPSR.cc:340
Coord getNeighborPosition(const L3Address &address) const
Definition: GPSR.cc:331
IMobility * mobility
Definition: GPSR.h:61
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
Coord inet::GPSR::getNeighborPosition ( const L3Address address) const
private

Referenced by findPerimeterRoutingNextHop(), and getNeighborAngle().

332 {
333  return neighborPositionTable.getPosition(address);
334 }
Coord getPosition(const L3Address &address) const
Definition: PositionTable.cc:38
PositionTable neighborPositionTable
Definition: GPSR.h:75
simtime_t inet::GPSR::getNextNeighborExpiration ( )
private

Referenced by schedulePurgeNeighborsTimer().

396 {
397  simtime_t oldestPosition = neighborPositionTable.getOldestPosition();
398  if (oldestPosition == SimTime::getMaxTime())
399  return oldestPosition;
400  else
401  return oldestPosition + neighborValidityInterval;
402 }
simtime_t getOldestPosition() const
Definition: PositionTable.cc:74
PositionTable neighborPositionTable
Definition: GPSR.h:75
simtime_t neighborValidityInterval
Definition: GPSR.h:56
L3Address inet::GPSR::getNextPlanarNeighborCounterClockwise ( const L3Address startNeighborAddress,
double  startNeighborAngle 
)
private

Referenced by findPerimeterRoutingNextHop().

454 {
455  EV_DEBUG << "Finding next planar neighbor (counter clockwise): startAddress = " << startNeighborAddress << ", startAngle = " << startNeighborAngle << endl;
456  L3Address bestNeighborAddress = startNeighborAddress;
457  double bestNeighborAngleDifference = 2 * M_PI;
458  std::vector<L3Address> neighborAddresses = getPlanarNeighbors();
459  for (auto & neighborAddress : neighborAddresses) {
460  double neighborAngle = getNeighborAngle(neighborAddress);
461  double neighborAngleDifference = neighborAngle - startNeighborAngle;
462  if (neighborAngleDifference < 0)
463  neighborAngleDifference += 2 * M_PI;
464  EV_DEBUG << "Trying next planar neighbor (counter clockwise): address = " << neighborAddress << ", angle = " << neighborAngle << endl;
465  if (neighborAngleDifference != 0 && neighborAngleDifference < bestNeighborAngleDifference) {
466  bestNeighborAngleDifference = neighborAngleDifference;
467  bestNeighborAddress = neighborAddress;
468  }
469  }
470  return bestNeighborAddress;
471 }
double getNeighborAngle(const L3Address &address)
Definition: GPSR.cc:353
std::vector< L3Address > getPlanarNeighbors()
Definition: GPSR.cc:409
#define M_PI
Definition: PlotFigure.cc:27
std::vector< L3Address > inet::GPSR::getPlanarNeighbors ( )
private

Referenced by getNextPlanarNeighborCounterClockwise().

410 {
411  std::vector<L3Address> planarNeighbors;
412  std::vector<L3Address> neighborAddresses = neighborPositionTable.getAddresses();
413  Coord selfPosition = mobility->getCurrentPosition();
414  for (auto it = neighborAddresses.begin(); it != neighborAddresses.end(); it++) {
415  const L3Address& neighborAddress = *it;
416  Coord neighborPosition = neighborPositionTable.getPosition(neighborAddress);
418  double neighborDistance = (neighborPosition - selfPosition).length();
419  for (auto & neighborAddresse : neighborAddresses) {
420  const L3Address& witnessAddress = neighborAddresse;
421  Coord witnessPosition = neighborPositionTable.getPosition(witnessAddress);
422  double witnessDistance = (witnessPosition - selfPosition).length();
423  ;
424  double neighborWitnessDistance = (witnessPosition - neighborPosition).length();
425  if (*it == neighborAddresse)
426  continue;
427  else if (neighborDistance > std::max(witnessDistance, neighborWitnessDistance))
428  goto eliminate;
429  }
430  }
432  Coord middlePosition = (selfPosition + neighborPosition) / 2;
433  double neighborDistance = (neighborPosition - middlePosition).length();
434  for (auto & neighborAddresse : neighborAddresses) {
435  const L3Address& witnessAddress = neighborAddresse;
436  Coord witnessPosition = neighborPositionTable.getPosition(witnessAddress);
437  double witnessDistance = (witnessPosition - middlePosition).length();
438  ;
439  if (*it == neighborAddresse)
440  continue;
441  else if (witnessDistance < neighborDistance)
442  goto eliminate;
443  }
444  }
445  else
446  throw cRuntimeError("Unknown planarization mode");
447  planarNeighbors.push_back(*it);
448  eliminate:;
449  }
450  return planarNeighbors;
451 }
Coord getPosition(const L3Address &address) const
Definition: PositionTable.cc:38
std::vector< L3Address > getAddresses() const
Definition: PositionTable.cc:24
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
PositionTable neighborPositionTable
Definition: GPSR.h:75
IMobility * mobility
Definition: GPSR.h:61
Definition: GPSRDefs.h:33
GPSRPlanarizationMode planarizationMode
Definition: GPSR.h:52
Definition: GPSRDefs.h:34
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
L3Address inet::GPSR::getSelfAddress ( ) const
private

Referenced by computeOptionLength(), createBeacon(), findGreedyRoutingNextHop(), findPerimeterRoutingNextHop(), initialize(), processBeaconTimer(), routeDatagram(), and sendBeacon().

368 {
369  //TODO choose self address based on a new 'interfaces' parameter
370  L3Address ret = routingTable->getRouterIdAsGeneric();
371 #ifdef WITH_IPv6
372  if (ret.getType() == L3Address::IPv6) {
373  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++) {
374  InterfaceEntry *ie = interfaceTable->getInterface(i);
375  if ((!ie->isLoopback()) && ie->ipv6Data() != nullptr) {
377  break;
378  }
379  }
380  }
381 #endif
382  return ret;
383 }
Definition: L3Address.h:47
const IPv6Address & getPreferredAddress() const
Chooses a preferred address for the interface and returns it.
Definition: IPv6InterfaceData.h:562
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
IRoutingTable * routingTable
Definition: GPSR.h:65
IPv6InterfaceData * ipv6Data() const
Definition: InterfaceEntry.h:223
IInterfaceTable * interfaceTable
Definition: GPSR.h:63
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
virtual L3Address getRouterIdAsGeneric() const =0
Returns routerId.
L3Address inet::GPSR::getSenderNeighborAddress ( INetworkDatagram datagram) const
private

Referenced by findPerimeterRoutingNextHop().

386 {
387  const GPSROption *gpsrOption = getGpsrOptionFromNetworkDatagram(datagram);
388  return gpsrOption->getSenderAddress();
389 }
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
double inet::GPSR::getVectorAngle ( Coord  vector)
staticprivate

Referenced by getDestinationAngle(), and getNeighborAngle().

341 {
342  double angle = atan2(-vector.y, vector.x);
343  if (angle < 0)
344  angle += 2 * M_PI;
345  return angle;
346 }
#define M_PI
Definition: PlotFigure.cc:27
void inet::GPSR::handleMessage ( cMessage *  message)
overrideprotected
111 {
112  if (message->isSelfMessage())
113  processSelfMessage(message);
114  else
115  processMessage(message);
116 }
void processSelfMessage(cMessage *message)
Definition: GPSR.cc:122
void processMessage(cMessage *message)
Definition: GPSR.cc:132
bool inet::GPSR::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprivatevirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

720 {
721  Enter_Method_Silent();
722  if (dynamic_cast<NodeStartOperation *>(operation)) {
725  }
726  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
728  // TODO: send a beacon to remove ourself from peers neighbor position table
730  cancelEvent(beaconTimer);
731  cancelEvent(purgeNeighborsTimer);
732  }
733  }
734  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
737  cancelEvent(beaconTimer);
738  cancelEvent(purgeNeighborsTimer);
739  }
740  }
741  else
742  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
743  return true;
744 }
cMessage * beaconTimer
Definition: GPSR.h:73
PositionTable neighborPositionTable
Definition: GPSR.h:75
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
Stage
Definition: NodeOperations.h:46
cMessage * purgeNeighborsTimer
Definition: GPSR.h:74
void clear()
Definition: PositionTable.cc:69
Definition: NodeOperations.h:127
void configureInterfaces()
Definition: GPSR.cc:289
void inet::GPSR::initialize ( int  stage)
overrideprotected
68 {
69  cSimpleModule::initialize(stage);
70 
71  if (stage == INITSTAGE_LOCAL) {
72  // GPSR parameters
73  planarizationMode = (GPSRPlanarizationMode)(int)par("planarizationMode");
74  interfaces = par("interfaces");
75  beaconInterval = par("beaconInterval");
76  maxJitter = par("maxJitter");
77  neighborValidityInterval = par("neighborValidityInterval");
78  // context
79  host = getContainingNode(this);
80  nodeStatus = dynamic_cast<NodeStatus *>(host->getSubmodule("status"));
81  interfaceTable = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
82  outputInterface = par("outputInterface");
83  mobility = check_and_cast<IMobility *>(host->getSubmodule("mobility"));
84  routingTable = getModuleFromPar<IRoutingTable>(par("routingTableModule"), this);
85  networkProtocol = getModuleFromPar<INetfilter>(par("networkProtocolModule"), this);
86  // internal
87  beaconTimer = new cMessage("BeaconTimer");
88  purgeNeighborsTimer = new cMessage("PurgeNeighborsTimer");
89 
90  // packet size
91  positionByteLength = par("positionByteLength");
92  }
93  else if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
94  IPSocket socket(gate("ipOut"));
95  socket.registerProtocol(IP_PROT_MANET);
96 
98  host->subscribe(NF_LINK_BREAK, this);
100  networkProtocol->registerHook(0, this);
101  if (isNodeUp()) {
105  }
106  WATCH(neighborPositionTable);
107  }
108 }
cMessage * beaconTimer
Definition: GPSR.h:73
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
static PositionTable globalPositionTable
Definition: GPSR.h:67
NodeStatus * nodeStatus
Definition: GPSR.h:60
GPSRPlanarizationMode
Definition: GPSRDefs.h:32
const char * outputInterface
Definition: GPSR.h:64
simtime_t beaconInterval
Definition: GPSR.h:54
simtime_t maxJitter
Definition: GPSR.h:55
Initialization of routing protocols.
Definition: InitStages.h:101
PositionTable neighborPositionTable
Definition: GPSR.h:75
Definition: IPProtocolId_m.h:93
Local initializations.
Definition: InitStages.h:35
int positionByteLength
Definition: GPSR.h:70
INetfilter * networkProtocol
Definition: GPSR.h:66
void schedulePurgeNeighborsTimer()
Definition: GPSR.cc:167
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
IL3AddressType * getAddressType() const
Definition: L3Address.cc:60
simtime_t neighborValidityInterval
Definition: GPSR.h:56
IMobility * mobility
Definition: GPSR.h:61
L3Address getSelfAddress() const
Definition: GPSR.cc:367
IRoutingTable * routingTable
Definition: GPSR.h:65
GPSRPlanarizationMode planarizationMode
Definition: GPSR.h:52
cMessage * purgeNeighborsTimer
Definition: GPSR.h:74
IInterfaceTable * interfaceTable
Definition: GPSR.h:63
IL3AddressType * addressType
Definition: GPSR.h:62
void scheduleBeaconTimer()
Definition: GPSR.cc:144
cModule * host
Definition: GPSR.h:59
void clear()
Definition: PositionTable.cc:69
const char * interfaces
Definition: GPSR.h:53
virtual void registerHook(int priority, IHook *hook)=0
Adds the provided hook to the list of registered hooks that will be called by the network layer when ...
void configureInterfaces()
Definition: GPSR.cc:289
bool isNodeUp() const
Definition: GPSR.cc:284
Coord inet::GPSR::intersectSections ( Coord begin1,
Coord end1,
Coord begin2,
Coord end2 
)
staticprivate

Referenced by findPerimeterRoutingNextHop().

305 {
306  double x1 = begin1.x;
307  double y1 = begin1.y;
308  double x2 = end1.x;
309  double y2 = end1.y;
310  double x3 = begin2.x;
311  double y3 = begin2.y;
312  double x4 = end2.x;
313  double y4 = end2.y;
314  double a = determinant(x1, y1, x2, y2);
315  double b = determinant(x3, y3, x4, y4);
316  double c = determinant(x1 - x2, y1 - y2, x3 - x4, y3 - y4);
317  double x = determinant(a, x1 - x2, b, x3 - x4) / c;
318  double y = determinant(a, y1 - y2, b, y3 - y4) / c;
319  if (x1 < x && x < x2 && x3 < x && x < x4 && y1 < y && y < y2 && y3 < y && y < y4)
320  return Coord(x, y, 0);
321  else
322  return Coord(NaN, NaN, NaN);
323 }
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
#define NaN
Definition: INETMath.h:103
value< double, units::m > b
Definition: Units.h:1054
bool inet::GPSR::isNodeUp ( ) const
private

Referenced by initialize().

285 {
286  return !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
287 }
NodeStatus * nodeStatus
Definition: GPSR.h:60
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual int inet::GPSR::numInitStages ( ) const
inlineoverrideprotectedvirtual
83 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::GPSR::processBeacon ( GPSRBeacon beacon)
private

Referenced by processUDPPacket().

246 {
247  EV_INFO << "Processing beacon: address = " << beacon->getAddress() << ", position = " << beacon->getPosition() << endl;
248  neighborPositionTable.setPosition(beacon->getAddress(), beacon->getPosition());
249  delete beacon;
250 }
PositionTable neighborPositionTable
Definition: GPSR.h:75
void setPosition(const L3Address &address, const Coord &coord)
Definition: PositionTable.cc:47
void inet::GPSR::processBeaconTimer ( )
private

Referenced by processSelfMessage().

151 {
152  EV_DEBUG << "Processing beacon timer" << endl;
153  L3Address selfAddress = getSelfAddress();
154  if (!selfAddress.isUnspecified()) {
155  sendBeacon(createBeacon(), uniform(0, maxJitter).dbl());
156  // KLUDGE: implement position registry protocol
158  }
161 }
static PositionTable globalPositionTable
Definition: GPSR.h:67
simtime_t maxJitter
Definition: GPSR.h:55
void sendBeacon(GPSRBeacon *beacon, double delay)
Definition: GPSR.cc:229
void schedulePurgeNeighborsTimer()
Definition: GPSR.cc:167
IMobility * mobility
Definition: GPSR.h:61
void setPosition(const L3Address &address, const Coord &coord)
Definition: PositionTable.cc:47
L3Address getSelfAddress() const
Definition: GPSR.cc:367
void scheduleBeaconTimer()
Definition: GPSR.cc:144
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
GPSRBeacon * createBeacon()
Definition: GPSR.cc:220
void inet::GPSR::processMessage ( cMessage *  message)
private

Referenced by handleMessage().

133 {
134  if (dynamic_cast<UDPPacket *>(message))
135  processUDPPacket(static_cast<UDPPacket *>(message));
136  else
137  throw cRuntimeError("Unknown message");
138 }
void processUDPPacket(UDPPacket *packet)
Definition: GPSR.cc:206
void inet::GPSR::processPurgeNeighborsTimer ( )
private

Referenced by processSelfMessage().

188 {
189  EV_DEBUG << "Processing purge neighbors timer" << endl;
190  purgeNeighbors();
192 }
void schedulePurgeNeighborsTimer()
Definition: GPSR.cc:167
void purgeNeighbors()
Definition: GPSR.cc:404
void inet::GPSR::processSelfMessage ( cMessage *  message)
private

Referenced by handleMessage().

123 {
124  if (message == beaconTimer)
126  else if (message == purgeNeighborsTimer)
128  else
129  throw cRuntimeError("Unknown self message");
130 }
cMessage * beaconTimer
Definition: GPSR.h:73
void processPurgeNeighborsTimer()
Definition: GPSR.cc:187
void processBeaconTimer()
Definition: GPSR.cc:150
cMessage * purgeNeighborsTimer
Definition: GPSR.h:74
void inet::GPSR::processUDPPacket ( UDPPacket packet)
private

Referenced by processMessage().

207 {
208  cPacket *encapsulatedPacket = packet->decapsulate();
209  if (dynamic_cast<GPSRBeacon *>(encapsulatedPacket))
210  processBeacon(static_cast<GPSRBeacon *>(encapsulatedPacket));
211  else
212  throw cRuntimeError("Unknown UDP packet");
213  delete packet;
214 }
void processBeacon(GPSRBeacon *beacon)
Definition: GPSR.cc:245
void inet::GPSR::purgeNeighbors ( )
private

Referenced by processPurgeNeighborsTimer().

405 {
407 }
void removeOldPositions(simtime_t timestamp)
Definition: PositionTable.cc:59
PositionTable neighborPositionTable
Definition: GPSR.h:75
simtime_t neighborValidityInterval
Definition: GPSR.h:56
void inet::GPSR::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprivatevirtual
751 {
752  Enter_Method("receiveChangeNotification");
753  if (signalID == NF_LINK_BREAK) {
754  EV_WARN << "Received link break" << endl;
755  // TODO: shall we remove the neighbor?
756  }
757 }
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
void inet::GPSR::removeGpsrOptionFromNetworkDatagram ( INetworkDatagram datagram)
private
INetfilter::IHook::Result inet::GPSR::routeDatagram ( INetworkDatagram datagram,
const InterfaceEntry *&  outputInterfaceEntry,
L3Address nextHop 
)
private

Referenced by datagramLocalOutHook(), and datagramPreRoutingHook().

573 {
574  const L3Address& source = datagram->getSourceAddress();
575  const L3Address& destination = datagram->getDestinationAddress();
576  EV_INFO << "Finding next hop: source = " << source << ", destination = " << destination << endl;
577  nextHop = findNextHop(datagram, destination);
578  if (nextHop.isUnspecified()) {
579  EV_WARN << "No next hop found, dropping packet: source = " << source << ", destination = " << destination << endl;
580  return DROP;
581  }
582  else {
583  EV_INFO << "Next hop found: source = " << source << ", destination = " << destination << ", nextHop: " << nextHop << endl;
584  GPSROption *gpsrOption = getGpsrOptionFromNetworkDatagram(datagram);
585  gpsrOption->setSenderAddress(getSelfAddress());
586  outputInterfaceEntry = interfaceTable->getInterfaceByName(outputInterface);
587  ASSERT(outputInterfaceEntry);
588  return ACCEPT;
589  }
590 }
doesn&#39;t allow the datagram to pass to the next hook, will be deleted
Definition: INetfilter.h:51
virtual InterfaceEntry * getInterfaceByName(const char *name) const =0
Returns an interface given by its name.
const char * outputInterface
Definition: GPSR.h:64
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
GPSROption * getGpsrOptionFromNetworkDatagram(INetworkDatagram *datagram)
Definition: GPSR.cc:681
L3Address getSelfAddress() const
Definition: GPSR.cc:367
IInterfaceTable * interfaceTable
Definition: GPSR.h:63
L3Address findNextHop(INetworkDatagram *datagram, const L3Address &destination)
Definition: GPSR.cc:477
void inet::GPSR::scheduleBeaconTimer ( )
private

Referenced by initialize(), and processBeaconTimer().

145 {
146  EV_DEBUG << "Scheduling beacon timer" << endl;
147  scheduleAt(simTime() + beaconInterval, beaconTimer);
148 }
cMessage * beaconTimer
Definition: GPSR.h:73
simtime_t beaconInterval
Definition: GPSR.h:54
void inet::GPSR::schedulePurgeNeighborsTimer ( )
private

Referenced by initialize(), processBeaconTimer(), and processPurgeNeighborsTimer().

168 {
169  EV_DEBUG << "Scheduling purge neighbors timer" << endl;
170  simtime_t nextExpiration = getNextNeighborExpiration();
171  if (nextExpiration == SimTime::getMaxTime()) {
172  if (purgeNeighborsTimer->isScheduled())
173  cancelEvent(purgeNeighborsTimer);
174  }
175  else {
176  if (!purgeNeighborsTimer->isScheduled())
177  scheduleAt(nextExpiration, purgeNeighborsTimer);
178  else {
179  if (purgeNeighborsTimer->getArrivalTime() != nextExpiration) {
180  cancelEvent(purgeNeighborsTimer);
181  scheduleAt(nextExpiration, purgeNeighborsTimer);
182  }
183  }
184  }
185 }
simtime_t getNextNeighborExpiration()
Definition: GPSR.cc:395
cMessage * purgeNeighborsTimer
Definition: GPSR.h:74
void inet::GPSR::sendBeacon ( GPSRBeacon beacon,
double  delay 
)
private

Referenced by processBeaconTimer().

230 {
231  EV_INFO << "Sending beacon: address = " << beacon->getAddress() << ", position = " << beacon->getPosition() << endl;
232  INetworkProtocolControlInfo *networkProtocolControlInfo = addressType->createNetworkProtocolControlInfo();
233  networkProtocolControlInfo->setTransportProtocol(IP_PROT_MANET);
234  networkProtocolControlInfo->setHopLimit(255);
235  networkProtocolControlInfo->setDestinationAddress(addressType->getLinkLocalManetRoutersMulticastAddress());
236  networkProtocolControlInfo->setSourceAddress(getSelfAddress());
237  UDPPacket *udpPacket = new UDPPacket(beacon->getName());
238  udpPacket->encapsulate(beacon);
239  udpPacket->setSourcePort(GPSR_UDP_PORT);
240  udpPacket->setDestinationPort(GPSR_UDP_PORT);
241  udpPacket->setControlInfo(dynamic_cast<cObject *>(networkProtocolControlInfo));
242  sendUDPPacket(udpPacket, delay);
243 }
virtual void setTransportProtocol(short Transportprotocol)=0
#define GPSR_UDP_PORT
Definition: GPSRDefs.h:23
Definition: IPProtocolId_m.h:93
void sendUDPPacket(UDPPacket *packet, double delay)
Definition: GPSR.cc:198
L3Address getSelfAddress() const
Definition: GPSR.cc:367
virtual INetworkProtocolControlInfo * createNetworkProtocolControlInfo() const =0
IL3AddressType * addressType
Definition: GPSR.h:62
virtual L3Address getLinkLocalManetRoutersMulticastAddress() const =0
void inet::GPSR::sendUDPPacket ( UDPPacket packet,
double  delay 
)
private

Referenced by sendBeacon().

199 {
200  if (delay == 0)
201  send(packet, "ipOut");
202  else
203  sendDelayed(packet, delay, "ipOut");
204 }
void inet::GPSR::setGpsrOptionOnNetworkDatagram ( INetworkDatagram datagram)
private

Referenced by datagramLocalOutHook().

593 {
594  cPacket *networkPacket = check_and_cast<cPacket *>(datagram);
595  GPSROption *gpsrOption = createGpsrOption(datagram->getDestinationAddress(), networkPacket->getEncapsulatedPacket());
596 #ifdef WITH_IPv4
597  if (dynamic_cast<IPv4Datagram *>(networkPacket)) {
598  gpsrOption->setType(IPOPTION_TLV_GPSR);
599  IPv4Datagram *dgram = static_cast<IPv4Datagram *>(networkPacket);
600  int oldHlen = dgram->calculateHeaderByteLength();
601  ASSERT(dgram->getHeaderLength() == oldHlen);
602  dgram->addOption(gpsrOption);
603  int newHlen = dgram->calculateHeaderByteLength();
604  dgram->setHeaderLength(newHlen);
605  dgram->addByteLength(newHlen - oldHlen);
606  dgram->setTotalLengthField(dgram->getTotalLengthField() + newHlen - oldHlen);
607  }
608  else
609 #endif
610 #ifdef WITH_IPv6
611  if (dynamic_cast<IPv6Datagram *>(networkPacket)) {
612  gpsrOption->setType(IPv6TLVOPTION_TLV_GPSR);
613  IPv6Datagram *dgram = static_cast<IPv6Datagram *>(networkPacket);
614  int oldHlen = dgram->calculateHeaderByteLength();
615  IPv6HopByHopOptionsHeader *hdr = check_and_cast_nullable<IPv6HopByHopOptionsHeader *>(dgram->findExtensionHeaderByType(IP_PROT_IPv6EXT_HOP));
616  if (hdr == nullptr) {
617  hdr = new IPv6HopByHopOptionsHeader();
618  hdr->setByteLength(8);
619  dgram->addExtensionHeader(hdr);
620  }
621  hdr->getTlvOptions().add(gpsrOption);
622  hdr->setByteLength(utils::roundUp(2 + hdr->getTlvOptions().getLength(), 8));
623  int newHlen = dgram->calculateHeaderByteLength();
624  dgram->addByteLength(newHlen - oldHlen);
625  }
626  else
627 #endif
628 #ifdef WITH_GENERIC
629  if (dynamic_cast<GenericDatagram *>(networkPacket)) {
630  gpsrOption->setType(GENERIC_TLVOPTION_TLV_GPSR);
631  GenericDatagram *dgram = static_cast<GenericDatagram *>(networkPacket);
632  int oldHlen = dgram->getTlvOptions().getLength();
633  dgram->getTlvOptions().add(gpsrOption);
634  int newHlen = dgram->getTlvOptions().getLength();
635  dgram->addByteLength(newHlen - oldHlen);
636  }
637  else
638 #endif
639  {
640  }
641 }
Definition: IPv6ExtensionHeaders_m.h:60
Definition: GenericDatagram_m.h:57
Definition: IPProtocolId_m.h:94
GPSROption * createGpsrOption(L3Address destination, cPacket *content)
Definition: GPSR.cc:256
int roundUp(int numToRound, int multiple)
Rounding up to the nearest multiple of a number.
Definition: INETUtils.h:69
virtual void setType(short type)
Definition: IPv4Datagram_m.h:114

Member Data Documentation

IL3AddressType* inet::GPSR::addressType = nullptr
private
simtime_t inet::GPSR::beaconInterval
private

Referenced by initialize(), and scheduleBeaconTimer().

cMessage* inet::GPSR::beaconTimer = nullptr
private
PositionTable inet::GPSR::globalPositionTable
staticprivate
cModule* inet::GPSR::host = nullptr
private

Referenced by getHostName(), and initialize().

const char* inet::GPSR::interfaces = nullptr
private

Referenced by configureInterfaces(), and initialize().

IInterfaceTable* inet::GPSR::interfaceTable = nullptr
private
simtime_t inet::GPSR::maxJitter
private

Referenced by initialize(), and processBeaconTimer().

simtime_t inet::GPSR::neighborValidityInterval
private
INetfilter* inet::GPSR::networkProtocol = nullptr
private

Referenced by initialize().

NodeStatus* inet::GPSR::nodeStatus = nullptr
private

Referenced by initialize(), and isNodeUp().

const char* inet::GPSR::outputInterface = nullptr
private

Referenced by initialize(), and routeDatagram().

GPSRPlanarizationMode inet::GPSR::planarizationMode = (GPSRPlanarizationMode)-1
private

Referenced by getPlanarNeighbors(), and initialize().

int inet::GPSR::positionByteLength = -1
private
cMessage* inet::GPSR::purgeNeighborsTimer = nullptr
private
IRoutingTable* inet::GPSR::routingTable = nullptr
private

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