INET Framework for OMNeT++/OMNEST
inet::ospf::LinkStateRequestHandler Class Reference

#include <LinkStateRequestHandler.h>

Inheritance diagram for inet::ospf::LinkStateRequestHandler:
inet::ospf::IMessageHandler

Public Member Functions

 LinkStateRequestHandler (Router *containingRouter)
 
void processPacket (OSPFPacket *packet, Interface *intf, Neighbor *neighbor) override
 
- Public Member Functions inherited from inet::ospf::IMessageHandler
 IMessageHandler (Router *containingRouter)
 
virtual ~IMessageHandler ()
 

Additional Inherited Members

- Protected Attributes inherited from inet::ospf::IMessageHandler
Routerrouter
 

Constructor & Destructor Documentation

inet::ospf::LinkStateRequestHandler::LinkStateRequestHandler ( Router containingRouter)
29  :
30  IMessageHandler(containingRouter)
31 {
32 }
IMessageHandler(Router *containingRouter)
Definition: IMessageHandler.h:38

Member Function Documentation

void inet::ospf::LinkStateRequestHandler::processPacket ( OSPFPacket packet,
Interface intf,
Neighbor neighbor 
)
overridevirtual

Implements inet::ospf::IMessageHandler.

Referenced by inet::ospf::MessageHandler::processPacket().

35 {
36  router->getMessageHandler()->printEvent("Link State Request packet received", intf, neighbor);
37 
38  Neighbor::NeighborStateType neighborState = neighbor->getState();
39 
40  if ((neighborState == Neighbor::EXCHANGE_STATE) ||
41  (neighborState == Neighbor::LOADING_STATE) ||
42  (neighborState == Neighbor::FULL_STATE))
43  {
44  OSPFLinkStateRequestPacket *lsRequestPacket = check_and_cast<OSPFLinkStateRequestPacket *>(packet);
45 
46  unsigned long requestCount = lsRequestPacket->getRequestsArraySize();
47  bool error = false;
48  std::vector<OSPFLSA *> lsas;
49 
50  EV_INFO << " Processing packet contents:\n";
51 
52  for (unsigned long i = 0; i < requestCount; i++) {
53  LSARequest& request = lsRequestPacket->getRequests(i);
54  LSAKeyType lsaKey;
55 
56  EV_INFO << " LSARequest: type=" << request.lsType
57  << ", LSID=" << request.linkStateID
58  << ", advertisingRouter=" << request.advertisingRouter
59  << "\n";
60 
61  lsaKey.linkStateID = request.linkStateID;
62  lsaKey.advertisingRouter = request.advertisingRouter;
63 
64  OSPFLSA *lsaInDatabase = router->findLSA(static_cast<LSAType>(request.lsType), lsaKey, intf->getArea()->getAreaID());
65 
66  if (lsaInDatabase != nullptr) {
67  lsas.push_back(lsaInDatabase);
68  }
69  else {
70  error = true;
71  neighbor->processEvent(Neighbor::BAD_LINK_STATE_REQUEST);
72  break;
73  }
74  }
75 
76  if (!error) {
77  int updatesCount = lsas.size();
78  int ttl = (intf->getType() == Interface::VIRTUAL) ? VIRTUAL_LINK_TTL : 1;
79  MessageHandler *messageHandler = router->getMessageHandler();
80 
81  for (int j = 0; j < updatesCount; j++) {
82  OSPFLinkStateUpdatePacket *updatePacket = intf->createUpdatePacket(lsas[j]);
83  if (updatePacket != nullptr) {
84  if (intf->getType() == Interface::BROADCAST) {
85  if ((intf->getState() == Interface::DESIGNATED_ROUTER_STATE) ||
86  (intf->getState() == Interface::BACKUP_STATE) ||
87  (intf->getDesignatedRouter() == NULL_DESIGNATEDROUTERID))
88  {
89  messageHandler->sendPacket(updatePacket, IPv4Address::ALL_OSPF_ROUTERS_MCAST, intf->getIfIndex(), ttl);
90  }
91  else {
92  messageHandler->sendPacket(updatePacket, IPv4Address::ALL_OSPF_DESIGNATED_ROUTERS_MCAST, intf->getIfIndex(), ttl);
93  }
94  }
95  else {
96  if (intf->getType() == Interface::POINTTOPOINT) {
97  messageHandler->sendPacket(updatePacket, IPv4Address::ALL_OSPF_ROUTERS_MCAST, intf->getIfIndex(), ttl);
98  }
99  else {
100  messageHandler->sendPacket(updatePacket, neighbor->getAddress(), intf->getIfIndex(), ttl);
101  }
102  }
103  }
104  }
105  // These update packets should not be placed on retransmission lists
106  }
107  }
108 }
#define VIRTUAL_LINK_TTL
Definition: OSPFcommon.h:45
void printEvent(const char *eventString, const Interface *onInterface=nullptr, const Neighbor *forNeighbor=nullptr) const
Definition: MessageHandler.cc:377
Definition: OSPFInterface.h:60
Router * router
Definition: IMessageHandler.h:35
NeighborStateType
Definition: OSPFNeighbor.h:61
Definition: OSPFInterface.h:56
Definition: OSPFNeighbor.h:68
const DesignatedRouterID NULL_DESIGNATEDROUTERID
Definition: OSPFcommon.h:164
Definition: OSPFInterface.h:57
OSPFLSA * findLSA(LSAType lsaType, LSAKeyType lsaKey, AreaID areaID)
Find the LSA identified by the input lsaKey in the database.
Definition: OSPFRouter.cc:230
Definition: OSPFInterface.h:69
void sendPacket(OSPFPacket *packet, IPv4Address destination, int outputIfIndex, short ttl=1)
Definition: MessageHandler.cc:305
Definition: OSPFNeighbor.h:69
MessageHandler * getMessageHandler()
Definition: OSPFRouter.h:77
Definition: OSPFNeighbor.h:67
static const IPv4Address ALL_OSPF_DESIGNATED_ROUTERS_MCAST
224.0.0.6 All OSPF Designated Routers
Definition: IPv4Address.h:111
uint8_t ttl
Definition: TCP_NSC.cc:87
static const IPv4Address ALL_OSPF_ROUTERS_MCAST
224.0.0.5 All OSPF routers (DR Others)
Definition: IPv4Address.h:110

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