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

#include <DatabaseDescriptionHandler.h>

Inheritance diagram for inet::ospf::DatabaseDescriptionHandler:
inet::ospf::IMessageHandler

Public Member Functions

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

Private Member Functions

bool processDDPacket (OSPFDatabaseDescriptionPacket *ddPacket, Interface *intf, Neighbor *neighbor, bool inExchangeStart)
 

Additional Inherited Members

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

Constructor & Destructor Documentation

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

Member Function Documentation

bool inet::ospf::DatabaseDescriptionHandler::processDDPacket ( OSPFDatabaseDescriptionPacket ddPacket,
Interface intf,
Neighbor neighbor,
bool  inExchangeStart 
)
private

Referenced by processPacket().

192 {
193  EV_INFO << " Processing packet contents(ddOptions="
194  << ((ddPacket->getDdOptions().I_Init) ? "I " : "_ ")
195  << ((ddPacket->getDdOptions().M_More) ? "M " : "_ ")
196  << ((ddPacket->getDdOptions().MS_MasterSlave) ? "MS" : "__")
197  << "; seqNumber="
198  << ddPacket->getDdSequenceNumber()
199  << "):\n";
200 
201  unsigned int headerCount = ddPacket->getLsaHeadersArraySize();
202 
203  for (unsigned int i = 0; i < headerCount; i++) {
204  OSPFLSAHeader& currentHeader = ddPacket->getLsaHeaders(i);
205  LSAType lsaType = static_cast<LSAType>(currentHeader.getLsType());
206 
207  EV_DETAIL << " " << currentHeader;
208 
209  if ((lsaType < ROUTERLSA_TYPE) || (lsaType > AS_EXTERNAL_LSA_TYPE) ||
210  ((lsaType == AS_EXTERNAL_LSA_TYPE) && (!intf->getArea()->getExternalRoutingCapability())))
211  {
212  EV_ERROR << " Error!\n";
213  neighbor->processEvent(Neighbor::SEQUENCE_NUMBER_MISMATCH);
214  return false;
215  }
216  else {
217  LSAKeyType lsaKey;
218 
219  lsaKey.linkStateID = currentHeader.getLinkStateID();
220  lsaKey.advertisingRouter = currentHeader.getAdvertisingRouter();
221 
222  OSPFLSA *lsaInDatabase = router->findLSA(lsaType, lsaKey, intf->getArea()->getAreaID());
223 
224  // operator< and operator== on OSPFLSAHeaders determines which one is newer(less means older)
225  if ((lsaInDatabase == nullptr) || (lsaInDatabase->getHeader() < currentHeader)) {
226  EV_DETAIL << " (newer)";
227  neighbor->addToRequestList(&currentHeader);
228  }
229  }
230  EV_DETAIL << "\n";
231  }
232 
233  if (neighbor->getDatabaseExchangeRelationship() == Neighbor::MASTER) {
234  neighbor->incrementDDSequenceNumber();
235  if ((neighbor->getDatabaseSummaryListCount() == 0) && !ddPacket->getDdOptions().M_More) {
236  neighbor->processEvent(Neighbor::EXCHANGE_DONE); // does nothing in ExchangeStart
237  }
238  else {
239  if (!inExchangeStart) {
240  neighbor->sendDatabaseDescriptionPacket();
241  }
242  }
243  }
244  else {
245  neighbor->setDDSequenceNumber(ddPacket->getDdSequenceNumber());
246  if (!inExchangeStart) {
247  neighbor->sendDatabaseDescriptionPacket();
248  }
249  if (!ddPacket->getDdOptions().M_More &&
250  (neighbor->getDatabaseSummaryListCount() == 0))
251  {
252  neighbor->processEvent(Neighbor::EXCHANGE_DONE); // does nothing in ExchangeStart
253  }
254  }
255  return true;
256 }
Router * router
Definition: IMessageHandler.h:35
OSPFLSA * findLSA(LSAType lsaType, LSAKeyType lsaKey, AreaID areaID)
Find the LSA identified by the input lsaKey in the database.
Definition: OSPFRouter.cc:230
Definition: OSPFNeighbor.h:46
Definition: OSPFPacket_m.h:245
LSAType
Enum generated from inet/routing/ospfv2/OSPFPacket.msg:84 by nedtool.
Definition: OSPFPacket_m.h:244
Definition: OSPFPacket_m.h:249
Definition: OSPFNeighbor.h:73
void inet::ospf::DatabaseDescriptionHandler::processPacket ( OSPFPacket packet,
Interface intf,
Neighbor neighbor 
)
overridevirtual

Implements inet::ospf::IMessageHandler.

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

35 {
36  router->getMessageHandler()->printEvent("Database Description packet received", intf, neighbor);
37 
38  OSPFDatabaseDescriptionPacket *ddPacket = check_and_cast<OSPFDatabaseDescriptionPacket *>(packet);
39 
40  Neighbor::NeighborStateType neighborState = neighbor->getState();
41 
42  if ((ddPacket->getInterfaceMTU() <= intf->getMTU()) &&
43  (neighborState > Neighbor::ATTEMPT_STATE))
44  {
45  switch (neighborState) {
47  break;
48 
50  neighbor->processEvent(Neighbor::TWOWAY_RECEIVED);
51  break;
52 
54  OSPFDDOptions& ddOptions = ddPacket->getDdOptions();
55 
56  if (ddOptions.I_Init && ddOptions.M_More && ddOptions.MS_MasterSlave &&
57  (ddPacket->getLsaHeadersArraySize() == 0))
58  {
59  if (neighbor->getNeighborID() > router->getRouterID()) {
60  Neighbor::DDPacketID packetID;
61  packetID.ddOptions = ddOptions;
62  packetID.options = ddPacket->getOptions();
63  packetID.sequenceNumber = ddPacket->getDdSequenceNumber();
64 
65  neighbor->setOptions(packetID.options);
66  neighbor->setDatabaseExchangeRelationship(Neighbor::SLAVE);
67  neighbor->setDDSequenceNumber(packetID.sequenceNumber);
68  neighbor->setLastReceivedDDPacket(packetID);
69 
70  if (!processDDPacket(ddPacket, intf, neighbor, true)) {
71  break;
72  }
73 
74  neighbor->processEvent(Neighbor::NEGOTIATION_DONE);
75  if (!neighbor->isLinkStateRequestListEmpty() &&
76  !neighbor->isRequestRetransmissionTimerActive())
77  {
78  neighbor->sendLinkStateRequestPacket();
79  neighbor->clearRequestRetransmissionTimer();
80  neighbor->startRequestRetransmissionTimer();
81  }
82  }
83  else {
84  neighbor->sendDatabaseDescriptionPacket(true);
85  }
86  }
87  if (!ddOptions.I_Init && !ddOptions.MS_MasterSlave &&
88  (ddPacket->getDdSequenceNumber() == neighbor->getDDSequenceNumber()) &&
89  (neighbor->getNeighborID() < router->getRouterID()))
90  {
91  Neighbor::DDPacketID packetID;
92  packetID.ddOptions = ddOptions;
93  packetID.options = ddPacket->getOptions();
94  packetID.sequenceNumber = ddPacket->getDdSequenceNumber();
95 
96  neighbor->setOptions(packetID.options);
97  neighbor->setDatabaseExchangeRelationship(Neighbor::MASTER);
98  neighbor->setLastReceivedDDPacket(packetID);
99 
100  if (!processDDPacket(ddPacket, intf, neighbor, true)) {
101  break;
102  }
103 
104  neighbor->processEvent(Neighbor::NEGOTIATION_DONE);
105  if (!neighbor->isLinkStateRequestListEmpty() &&
106  !neighbor->isRequestRetransmissionTimerActive())
107  {
108  neighbor->sendLinkStateRequestPacket();
109  neighbor->clearRequestRetransmissionTimer();
110  neighbor->startRequestRetransmissionTimer();
111  }
112  }
113  }
114  break;
115 
117  Neighbor::DDPacketID packetID;
118  packetID.ddOptions = ddPacket->getDdOptions();
119  packetID.options = ddPacket->getOptions();
120  packetID.sequenceNumber = ddPacket->getDdSequenceNumber();
121 
122  if (packetID != neighbor->getLastReceivedDDPacket()) {
123  if ((packetID.ddOptions.MS_MasterSlave &&
124  (neighbor->getDatabaseExchangeRelationship() != Neighbor::SLAVE)) ||
125  (!packetID.ddOptions.MS_MasterSlave &&
126  (neighbor->getDatabaseExchangeRelationship() != Neighbor::MASTER)) ||
127  packetID.ddOptions.I_Init ||
128  (packetID.options != neighbor->getLastReceivedDDPacket().options))
129  {
130  neighbor->processEvent(Neighbor::SEQUENCE_NUMBER_MISMATCH);
131  }
132  else {
133  if (((neighbor->getDatabaseExchangeRelationship() == Neighbor::MASTER) &&
134  (packetID.sequenceNumber == neighbor->getDDSequenceNumber())) ||
135  ((neighbor->getDatabaseExchangeRelationship() == Neighbor::SLAVE) &&
136  (packetID.sequenceNumber == (neighbor->getDDSequenceNumber() + 1))))
137  {
138  neighbor->setLastReceivedDDPacket(packetID);
139  if (!processDDPacket(ddPacket, intf, neighbor, false)) {
140  break;
141  }
142  if (!neighbor->isLinkStateRequestListEmpty() &&
143  !neighbor->isRequestRetransmissionTimerActive())
144  {
145  neighbor->sendLinkStateRequestPacket();
146  neighbor->clearRequestRetransmissionTimer();
147  neighbor->startRequestRetransmissionTimer();
148  }
149  }
150  else {
151  neighbor->processEvent(Neighbor::SEQUENCE_NUMBER_MISMATCH);
152  }
153  }
154  }
155  else {
156  if (neighbor->getDatabaseExchangeRelationship() == Neighbor::SLAVE) {
157  neighbor->retransmitDatabaseDescriptionPacket();
158  }
159  }
160  }
161  break;
162 
164  case Neighbor::FULL_STATE: {
165  Neighbor::DDPacketID packetID;
166  packetID.ddOptions = ddPacket->getDdOptions();
167  packetID.options = ddPacket->getOptions();
168  packetID.sequenceNumber = ddPacket->getDdSequenceNumber();
169 
170  if ((packetID != neighbor->getLastReceivedDDPacket()) ||
171  (packetID.ddOptions.I_Init))
172  {
173  neighbor->processEvent(Neighbor::SEQUENCE_NUMBER_MISMATCH);
174  }
175  else {
176  if (neighbor->getDatabaseExchangeRelationship() == Neighbor::SLAVE) {
177  if (!neighbor->retransmitDatabaseDescriptionPacket()) {
178  neighbor->processEvent(Neighbor::SEQUENCE_NUMBER_MISMATCH);
179  }
180  }
181  }
182  }
183  break;
184 
185  default:
186  break;
187  }
188  }
189 }
Definition: OSPFNeighbor.h:74
Definition: OSPFNeighbor.h:64
Definition: OSPFNeighbor.h:66
Definition: OSPFNeighbor.h:65
void printEvent(const char *eventString, const Interface *onInterface=nullptr, const Neighbor *forNeighbor=nullptr) const
Definition: MessageHandler.cc:377
Router * router
Definition: IMessageHandler.h:35
Definition: OSPFNeighbor.h:63
Definition: OSPFNeighbor.h:44
NeighborStateType
Definition: OSPFNeighbor.h:61
RouterID getRouterID() const
Definition: OSPFRouter.h:72
Definition: OSPFNeighbor.h:45
Definition: OSPFNeighbor.h:68
bool processDDPacket(OSPFDatabaseDescriptionPacket *ddPacket, Interface *intf, Neighbor *neighbor, bool inExchangeStart)
Definition: DatabaseDescriptionHandler.cc:191
Definition: OSPFNeighbor.h:73
Definition: OSPFNeighbor.h:69
MessageHandler * getMessageHandler()
Definition: OSPFRouter.h:77
Definition: OSPFNeighbor.h:67

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