View | Details | Raw Unified | Return to bug 1609
Collapse All | Expand All

(-)ns3dev/src/dsr/model/dsr-options.cc (-40 / +135 lines)
 Lines 217-222   Ipv4Address DsrOptions::ReverseSearchNex Link Here 
217
  return none;
217
  return none;
218
}
218
}
219
219
220
Ipv4Address DsrOptions::ReverseSearchNextTwoHop  (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
221
{
222
  NS_LOG_FUNCTION (this << ipv4Address);
223
  Ipv4Address nextTwoHop;
224
  NS_LOG_DEBUG ("The vector size " << vec.size ());
225
  NS_ASSERT (vec.size () > 2);
226
  for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri)
227
    {
228
      if (ipv4Address == (*ri))
229
        {
230
          nextTwoHop = *(ri + 2);
231
          return nextTwoHop;
232
        }
233
    }
234
  NS_FATAL_ERROR ("next hop address not found, route corrupted");
235
  Ipv4Address none = "0.0.0.0";
236
  return none;
237
}
238
220
void DsrOptions::PrintVector (std::vector<Ipv4Address>& vec)
239
void DsrOptions::PrintVector (std::vector<Ipv4Address>& vec)
221
{
240
{
222
  NS_LOG_FUNCTION (this);
241
  NS_LOG_FUNCTION (this);
 Lines 240-249   void DsrOptions::PrintVector (std::vecto Link Here 
240
bool DsrOptions::IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2)
259
bool DsrOptions::IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2)
241
{
260
{
242
  NS_LOG_FUNCTION (this);
261
  NS_LOG_FUNCTION (this);
243
  NS_LOG_DEBUG ("The first vector ");
244
  PrintVector (vec);
245
  NS_LOG_DEBUG ("The second vector ");
246
  PrintVector (vec2);
247
  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
262
  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
248
    {
263
    {
249
      for (std::vector<Ipv4Address>::const_iterator j = vec2.begin (); j != vec2.end (); ++j)
264
      for (std::vector<Ipv4Address>::const_iterator j = vec2.begin (); j != vec2.end (); ++j)
 Lines 384-390   uint8_t DsrOptionPad1::GetOptionNumber ( Link Here 
384
  return OPT_NUMBER;
399
  return OPT_NUMBER;
385
}
400
}
386
401
387
uint8_t DsrOptionPad1::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
402
uint8_t DsrOptionPad1::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
388
{
403
{
389
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
404
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
390
  Ptr<Packet> p = packet->Copy ();
405
  Ptr<Packet> p = packet->Copy ();
 Lines 423-429   uint8_t DsrOptionPadn::GetOptionNumber ( Link Here 
423
  return OPT_NUMBER;
438
  return OPT_NUMBER;
424
}
439
}
425
440
426
uint8_t DsrOptionPadn::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
441
uint8_t DsrOptionPadn::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
427
{
442
{
428
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
443
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
429
444
 Lines 469-475   uint8_t DsrOptionRreq::GetOptionNumber ( Link Here 
469
  return OPT_NUMBER;
484
  return OPT_NUMBER;
470
}
485
}
471
486
472
uint8_t DsrOptionRreq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
487
uint8_t DsrOptionRreq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
473
{
488
{
474
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
489
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
475
  // Fields from IP header
490
  // Fields from IP header
 Lines 490-496   uint8_t DsrOptionRreq::Process (Ptr<Pack Link Here 
490
  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
505
  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
491
  Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> ();
506
  Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> ();
492
507
493
  Ptr<Packet> p = packet->Copy (); // The packet here doesn't contain the fixed size dsr header
508
  Ptr<Packet> p = packet->Copy (); // Note: The packet here doesn't contain the fixed size dsr header
494
  /*
509
  /*
495
   * \brief Get the number of routers' address field before removing the header
510
   * \brief Get the number of routers' address field before removing the header
496
   * \peek the packet and get the value
511
   * \peek the packet and get the value
 Lines 524-537   uint8_t DsrOptionRreq::Process (Ptr<Pack Link Here 
524
      m_dropTrace (packet); // call drop trace
539
      m_dropTrace (packet); // call drop trace
525
      return 0;
540
      return 0;
526
    }
541
    }
542
  // Check the rreq id for verifying the request id
543
  uint16_t requestId = rreq.GetId ();
527
  // The target address is where we want to send the data packets
544
  // The target address is where we want to send the data packets
528
  Ipv4Address targetAddress = rreq.GetTarget ();
545
  Ipv4Address targetAddress = rreq.GetTarget ();
529
  // Get the node list and source address from the route request header
546
  // Get the node list and source address from the route request header
530
  std::vector<Ipv4Address> mainVector = rreq.GetNodesAddresses ();
547
  std::vector<Ipv4Address> mainVector = rreq.GetNodesAddresses ();
531
  std::vector<Ipv4Address> nodeList (mainVector);
548
  std::vector<Ipv4Address> nodeList (mainVector);
549
  // Get the real source address of this request, it will be used when checking if we have received the save
550
  // route request before or not
551
  Ipv4Address sourceAddress = nodeList.front ();
532
  PrintVector (nodeList);
552
  PrintVector (nodeList);
533
  /*
553
  /*
534
   * Construct the dsr routing header for future use
554
   * Construct the dsr routing header for later use
535
   */
555
   */
536
  DsrRoutingHeader dsrRoutingHeader;
556
  DsrRoutingHeader dsrRoutingHeader;
537
  dsrRoutingHeader.SetNextHeader (protocol);
557
  dsrRoutingHeader.SetNextHeader (protocol);
 Lines 539-545   uint8_t DsrOptionRreq::Process (Ptr<Pack Link Here 
539
  dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
559
  dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
540
  dsrRoutingHeader.SetDestId (255);
560
  dsrRoutingHeader.SetDestId (255);
541
561
542
  if (CheckDuplicates (ipv4Address, nodeList))
562
  // check whether we have received this request or not, if not, it will save the request in the table for
563
  // later use, if not found, return false, and push the newly received source request entry in the cache
564
565
  bool dupRequest = dsr->FindSourceEntry (sourceAddress, targetAddress, requestId);
566
  /*
567
   * Before processing the route request, we need to check two things
568
   * 1. if this is the exact same request we have just received, ignore it
569
   * 2. if our address is already in the path list, ignore it
570
   * 3. otherwise process further
571
   */
572
  if (dupRequest)
573
    {
574
      NS_LOG_DEBUG ("We have received duplicate request");
575
      // We have received this same route reqeust before, not forwarding it now
576
      NS_LOG_LOGIC ("Duplicate request. Drop!");
577
      m_dropTrace (packet); // call drop trace
578
      return 0;
579
    }
580
581
  else if (CheckDuplicates (ipv4Address, nodeList))
543
    {
582
    {
544
      /*
583
      /*
545
       * if the route contains the node address already, drop the request packet
584
       * if the route contains the node address already, drop the request packet
 Lines 552-557   uint8_t DsrOptionRreq::Process (Ptr<Pack Link Here 
552
    {
591
    {
553
      // A node ignores all RREQs received from any node in its blacklist
592
      // A node ignores all RREQs received from any node in its blacklist
554
      RouteCacheEntry toPrev;
593
      RouteCacheEntry toPrev;
594
555
      /*
595
      /*
556
       *  When the reverse route is created or updated, the following actions on the route are also carried out:
596
       *  When the reverse route is created or updated, the following actions on the route are also carried out:
557
       *  3. the next hop in the routing table becomes the node from which the  RREQ was received
597
       *  3. the next hop in the routing table becomes the node from which the  RREQ was received
 Lines 741-747   uint8_t DsrOptionRreq::Process (Ptr<Pack Link Here 
741
781
742
                  if (addRoute)
782
                  if (addRoute)
743
                    {
783
                    {
744
                      NS_LOG_DEBUG ("We have added the route and search send buffer for packet with destination " << dst);
784
                      NS_LOG_LOGIC ("We have added the route and search send buffer for packet with destination " << dst);
745
                      /*
785
                      /*
746
                       * Found a route the dst, construct the source route option header
786
                       * Found a route the dst, construct the source route option header
747
                       */
787
                       */
 Lines 935-941   uint8_t DsrOptionRrep::GetOptionNumber ( Link Here 
935
  return OPT_NUMBER;
975
  return OPT_NUMBER;
936
}
976
}
937
977
938
uint8_t DsrOptionRrep::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
978
uint8_t DsrOptionRrep::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
939
{
979
{
940
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
980
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
941
981
 Lines 1134-1140   uint8_t DsrOptionSR::GetOptionNumber () Link Here 
1134
  return OPT_NUMBER;
1174
  return OPT_NUMBER;
1135
}
1175
}
1136
1176
1137
uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
1177
uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1138
{
1178
{
1139
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Address << ipv4Header << (uint32_t)protocol << isPromisc);
1179
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Address << ipv4Header << (uint32_t)protocol << isPromisc);
1140
  Ptr<Packet> p = packet->Copy ();
1180
  Ptr<Packet> p = packet->Copy ();
 Lines 1149-1154   uint8_t DsrOptionSR::Process (Ptr<Packet Link Here 
1149
  // The route size saved in the source route
1189
  // The route size saved in the source route
1150
  std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1190
  std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1151
  uint8_t segsLeft = sourceRoute.GetSegmentsLeft ();
1191
  uint8_t segsLeft = sourceRoute.GetSegmentsLeft ();
1192
  /// TODO remove this one later
1193
  NS_LOG_DEBUG ("The segment left here " <<  (uint32_t) segsLeft);
1152
  uint8_t salvage = sourceRoute.GetSalvage ();
1194
  uint8_t salvage = sourceRoute.GetSalvage ();
1153
  /*
1195
  /*
1154
   * Get the node from IP address and get the DSR extension object
1196
   * Get the node from IP address and get the DSR extension object
 Lines 1160-1165   uint8_t DsrOptionSR::Process (Ptr<Packet Link Here 
1160
   */
1202
   */
1161
  Ipv4Address srcAddress = ipv4Header.GetSource ();
1203
  Ipv4Address srcAddress = ipv4Header.GetSource ();
1162
  Ipv4Address destAddress = ipv4Header.GetDestination ();
1204
  Ipv4Address destAddress = ipv4Header.GetDestination ();
1205
1163
  // Get the node list destination
1206
  // Get the node list destination
1164
  Ipv4Address destination = nodeList.back ();
1207
  Ipv4Address destination = nodeList.back ();
1165
  /*
1208
  /*
 Lines 1169-1194   uint8_t DsrOptionSR::Process (Ptr<Packet Link Here 
1169
   */
1212
   */
1170
  if (isPromisc)
1213
  if (isPromisc)
1171
    {
1214
    {
1172
      /*
1215
      NS_LOG_LOGIC ("We process promiscuous receipt data packet");
1173
       * Get the node from Ip address and get the dsr routing object
1174
       */
1175
      Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1176
      Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> ();
1177
      bool findSame = dsr->FindSamePackets (packet, source, destination, segsLeft);
1178
1179
      if (findSame)
1180
        {
1181
          NS_LOG_DEBUG ("Received one passive acknowledgment for a successfully delivered packet");
1182
        }
1183
      if (ContainAddressAfter (ipv4Address, destAddress, nodeList))
1216
      if (ContainAddressAfter (ipv4Address, destAddress, nodeList))
1184
        {
1217
        {
1185
          NS_LOG_DEBUG ("Send back the gratuitous reply");
1218
          NS_LOG_LOGIC ("Send back the gratuitous reply");
1186
          dsr->SendGratuitousReply (source, srcAddress, nodeList, protocol);
1219
          dsr->SendGratuitousReply (source, srcAddress, nodeList, protocol);
1187
        }
1220
        }
1188
      else
1221
1222
      uint16_t fragmentOffset = ipv4Header.GetFragmentOffset ();
1223
      uint16_t identification = ipv4Header.GetIdentification ();
1224
1225
      /// TODO add the link ack over here
1226
1227
      if (destAddress != destination)
1189
        {
1228
        {
1190
          return 0;
1229
          NS_LOG_DEBUG ("Process the promiscuously received packet");
1230
          bool findPassive;
1231
          int32_t nNodes = NodeList::GetNNodes ();
1232
          for (int32_t i = 0; i < nNodes; ++i)
1233
            {
1234
              NS_LOG_DEBUG ("Working with node " << i);
1235
1236
              Ptr<Node> node = NodeList::GetNode (i);
1237
              Ptr<dsr::DsrRouting> dsrNode = node->GetObject<dsr::DsrRouting> ();
1238
              // The source and destination addresses here are the real source and destination for the packet
1239
              findPassive = dsrNode->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, false);
1240
              if (findPassive)
1241
                {
1242
                  break;
1243
                }
1244
            }
1245
1246
          if (findPassive)
1247
            {
1248
              NS_LOG_DEBUG ("We find one previously received passive entry");
1249
              /*
1250
               * Get the node from IP address and get the DSR extension object
1251
               * the srcAddress would be the source address from ip header
1252
               */
1253
              PrintVector (nodeList);
1254
1255
              NS_LOG_DEBUG ("promisc source " << promiscSource);
1256
              Ptr<Node> node = GetNodeWithAddress (promiscSource);
1257
              Ptr<dsr::DsrRouting> dsrSrc = node->GetObject<dsr::DsrRouting> ();
1258
1259
              /// TODO need to think about this part
1260
              /// TODO this is temporarily disabled to enable other
1261
              dsrSrc->CancelPassiveTimer (packet, source, destination, segsLeft);
1262
            }
1263
          else
1264
            {
1265
              NS_LOG_DEBUG ("Saved the entry for further use");
1266
              dsr->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, true);
1267
            }
1191
        }
1268
        }
1269
      /// Safely terminate promiscuously received packet
1270
      return 0;
1192
    }
1271
    }
1193
  else
1272
  else
1194
    {
1273
    {
 Lines 1205-1227   uint8_t DsrOptionSR::Process (Ptr<Packet Link Here 
1205
      p->CopyData (data, size);
1284
      p->CopyData (data, size);
1206
      uint8_t optionType = 0;
1285
      uint8_t optionType = 0;
1207
      optionType = *(data);
1286
      optionType = *(data);
1208
      NS_LOG_DEBUG ("The packet size over here " << p->GetSize ());
1287
      /// When the option type is 160, means there is ACK request header after the source route, we need
1209
1288
      /// to send back acknowledgment
1210
      NS_LOG_DEBUG ("The option type over here " << (uint32_t)optionType);
1211
      if (optionType == 160)
1289
      if (optionType == 160)
1212
        {
1290
        {
1213
          NS_LOG_DEBUG ("Here we remove the ack request header and add ack header to the packet");
1291
          NS_LOG_LOGIC ("Remove the ack request header and add ack header to the packet");
1214
          // Here we remove the ack packet to the previous hop
1292
          // Here we remove the ack packet to the previous hop
1215
          DsrOptionAckReqHeader ackReq;
1293
          DsrOptionAckReqHeader ackReq;
1216
          p->RemoveHeader (ackReq);
1294
          p->RemoveHeader (ackReq);
1217
          uint16_t ackId = ackReq.GetAckId ();
1295
          uint16_t ackId = ackReq.GetAckId ();
1218
          NS_LOG_DEBUG ("The type value " << (uint32_t)ackReq.GetType ());
1219
          /*
1296
          /*
1220
           * Send back acknowledgment packet to the earlier hop
1297
           * Send back acknowledgment packet to the earlier hop
1298
           * If the node list is not empty, find the previous hop from the node list,
1299
           * otherwise, use srcAddress
1221
           */
1300
           */
1222
          m_ipv4Route = SetRoute (srcAddress, ipv4Address);
1301
          Ipv4Address ackAddress = srcAddress;
1223
          NS_LOG_DEBUG ("Send back ACK to the earlier hop " << srcAddress << " from us " << ipv4Address);
1302
          if (!nodeList.empty ())
1224
          dsr->SendAck (ackId, srcAddress, source, destination, protocol, m_ipv4Route);
1303
            {
1304
                if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses
1305
                  {
1306
                    NS_LOG_LOGIC ("Malformed header. Drop!");
1307
                    m_dropTrace (packet);
1308
                    return 0;
1309
                  }
1310
                if (numberAddress - segsLeft - 2 < 0) // The index is invalid
1311
                   {
1312
                      NS_LOG_LOGIC ("Malformed header. Drop!");
1313
                      m_dropTrace (packet);
1314
                      return 0;
1315
                   }
1316
                   ackAddress = nodeList[numberAddress - segsLeft - 2];
1317
            }
1318
           m_ipv4Route = SetRoute (ackAddress, ipv4Address);
1319
           NS_LOG_DEBUG ("Send back ACK to the earlier hop " << ackAddress << " from us " << ipv4Address);
1320
           dsr->SendAck (ackId, ackAddress, source, destination, protocol, m_ipv4Route);
1225
        }
1321
        }
1226
      /*
1322
      /*
1227
       * After send back ACK, check if the segments left value has turned to 0 or not, if yes, update the route entry
1323
       * After send back ACK, check if the segments left value has turned to 0 or not, if yes, update the route entry
 Lines 1325-1331   uint8_t DsrOptionRerr::GetOptionNumber ( Link Here 
1325
  return OPT_NUMBER;
1421
  return OPT_NUMBER;
1326
}
1422
}
1327
1423
1328
uint8_t DsrOptionRerr::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
1424
uint8_t DsrOptionRerr::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1329
{
1425
{
1330
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1426
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1331
  Ptr<Packet> p = packet->Copy ();
1427
  Ptr<Packet> p = packet->Copy ();
 Lines 1356-1362   uint8_t DsrOptionRerr::Process (Ptr<Pack Link Here 
1356
      Ipv4Address unreachAddress = rerrUnreach.GetUnreachNode ();
1452
      Ipv4Address unreachAddress = rerrUnreach.GetUnreachNode ();
1357
      Ipv4Address errorSource = rerrUnreach.GetErrorSrc ();
1453
      Ipv4Address errorSource = rerrUnreach.GetErrorSrc ();
1358
1454
1359
      NS_LOG_DEBUG ("The destination address and the unreachable node " << rerrUnreach.GetErrorDst () << " " << unreachAddress);
1455
      NS_LOG_DEBUG ("The error source is " <<  rerrUnreach.GetErrorDst () << "and the unreachable node is " << unreachAddress);
1360
      /*
1456
      /*
1361
       * Get the serialized size of the rerr header
1457
       * Get the serialized size of the rerr header
1362
       */
1458
       */
 Lines 1504-1510   uint8_t DsrOptionAckReq::GetOptionNumber Link Here 
1504
  return OPT_NUMBER;
1600
  return OPT_NUMBER;
1505
}
1601
}
1506
1602
1507
uint8_t DsrOptionAckReq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
1603
uint8_t DsrOptionAckReq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1508
{
1604
{
1509
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1605
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1510
  /*
1606
  /*
 Lines 1525-1531   uint8_t DsrOptionAckReq::Process (Ptr<Pa Link Here 
1525
  NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol);
1621
  NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol);
1526
1622
1527
  Ipv4Address srcAddress = ipv4Header.GetSource ();
1623
  Ipv4Address srcAddress = ipv4Header.GetSource ();
1528
  SetRoute (srcAddress, ipv4Address);
1529
1624
1530
  return ackReq.GetSerializedSize ();
1625
  return ackReq.GetSerializedSize ();
1531
}
1626
}
 Lines 1562-1568   uint8_t DsrOptionAck::GetOptionNumber () Link Here 
1562
  return OPT_NUMBER;
1657
  return OPT_NUMBER;
1563
}
1658
}
1564
1659
1565
uint8_t DsrOptionAck::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc)
1660
uint8_t DsrOptionAck::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1566
{
1661
{
1567
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1662
  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1568
  /*
1663
  /*
(-)ns3dev/src/dsr/model/dsr-options.h (-16 / +29 lines)
 Lines 112-118   public: Link Here 
112
   * \return the vector after the route cut
112
   * \return the vector after the route cut
113
   */
113
   */
114
  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
114
  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
115
  /*
115
  /**
116
   * \brief Set the route to use for data packets
116
   * \brief Set the route to use for data packets
117
   * \return the route
117
   * \return the route
118
   * \used by the option headers when sending data/control packets
118
   * \used by the option headers when sending data/control packets
 Lines 123-139   public: Link Here 
123
   * \return true if successfully reversed
123
   * \return true if successfully reversed
124
   */
124
   */
125
  bool ReverseRoutes  (std::vector<Ipv4Address>& vec);
125
  bool ReverseRoutes  (std::vector<Ipv4Address>& vec);
126
  /*
126
  /**
127
   * \brief Search for the next hop in the route
127
   * \brief Search for the next hop in the route
128
   * \return the next hop address if found
128
   * \return the next hop address if found
129
   */
129
   */
130
  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
130
  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
131
  /*
131
  /**
132
   * \brief Reverse search for the next hop in the route
132
   * \brief Reverse search for the next hop in the route
133
   * \return the next hop address if found
133
   * \return the previous next hop address if found
134
   */
134
   */
135
  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
135
  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
136
  /*
136
  /**
137
   * \brief Reverse search for the next two hop in the route
138
   * \return the previous next two hop address if found
139
   */
140
  Ipv4Address ReverseSearchNextTwoHop  (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
141
  /**
137
   * \brief Print out the elements in the route vector
142
   * \brief Print out the elements in the route vector
138
   */
143
   */
139
  void PrintVector (std::vector<Ipv4Address>& vec);
144
  void PrintVector (std::vector<Ipv4Address>& vec);
 Lines 152-163   public: Link Here 
152
   * \return the route after route shorten
157
   * \return the route after route shorten
153
   */
158
   */
154
  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
159
  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
155
  /*
160
  /**
161
   * \brief Schedule the intermediate node route request broadcast
162
   * \param the original packet
163
   * \param rrepHeader The rrep header
164
   * \param source address
165
   * \param destination address
166
   */
167
  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
168
  /**
156
   * \brief Get the node id with Ipv4Address
169
   * \brief Get the node id with Ipv4Address
157
   * \return the id of the node
170
   * \return the id of the node
158
   */
171
   */
159
  uint32_t GetIDfromIP (Ipv4Address address);
172
  uint32_t GetIDfromIP (Ipv4Address address);
160
  /*
173
  /**
161
   * \brief Get the node object with Ipv4Address
174
   * \brief Get the node object with Ipv4Address
162
   * \return the object of the node
175
   * \return the object of the node
163
   */
176
   */
 Lines 173-179   public: Link Here 
173
   * \param isPromisc if the packet must be dropped
186
   * \param isPromisc if the packet must be dropped
174
   * \return the processed size
187
   * \return the processed size
175
   */
188
   */
176
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc) = 0;
189
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) = 0;
177
190
178
protected:
191
protected:
179
  /**
192
  /**
 Lines 261-267   public: Link Here 
261
   * \param isPromisc if the packet must be dropped
274
   * \param isPromisc if the packet must be dropped
262
   * \return the processed size
275
   * \return the processed size
263
   */
276
   */
264
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
277
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
265
};
278
};
266
279
267
/**
280
/**
 Lines 304-310   public: Link Here 
304
   * \param isPromisc if the packet must be dropped
317
   * \param isPromisc if the packet must be dropped
305
   * \return the processed size
318
   * \return the processed size
306
   */
319
   */
307
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
320
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
308
};
321
};
309
322
310
/**
323
/**
 Lines 352-358   public: Link Here 
352
   * \param isPromisc if the packet must be dropped
365
   * \param isPromisc if the packet must be dropped
353
   * \return the processed size
366
   * \return the processed size
354
   */
367
   */
355
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
368
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
356
369
357
private:
370
private:
358
  /**
371
  /**
 Lines 410-416   public: Link Here 
410
   * \param isPromisc if the packet must be dropped
423
   * \param isPromisc if the packet must be dropped
411
   * \return the processed size
424
   * \return the processed size
412
   */
425
   */
413
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
426
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
414
427
415
private:
428
private:
416
  /**
429
  /**
 Lines 472-478   public: Link Here 
472
   * \param isPromisc if the packet must be dropped
485
   * \param isPromisc if the packet must be dropped
473
   * \return the processed size
486
   * \return the processed size
474
   */
487
   */
475
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
488
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
476
489
477
private:
490
private:
478
  /**
491
  /**
 Lines 530-536   public: Link Here 
530
   * \param isPromisc if the packet must be dropped
543
   * \param isPromisc if the packet must be dropped
531
   * \return the processed size
544
   * \return the processed size
532
   */
545
   */
533
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
546
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
534
  /**
547
  /**
535
   * \brief Do Send error message
548
   * \brief Do Send error message
536
   *
549
   *
 Lines 603-609   public: Link Here 
603
   * \param isPromisc if the packet must be dropped
616
   * \param isPromisc if the packet must be dropped
604
   * \return the processed size
617
   * \return the processed size
605
   */
618
   */
606
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
619
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
607
620
608
private:
621
private:
609
  /**
622
  /**
 Lines 665-671   public: Link Here 
665
   * \param isPromisc if the packet must be dropped
678
   * \param isPromisc if the packet must be dropped
666
   * \return the processed size
679
   * \return the processed size
667
   */
680
   */
668
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
681
  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
669
682
670
private:
683
private:
671
  /**
684
  /**
(-)ns3dev/src/dsr/model/dsr-passive-buff.cc (+213 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2011 Yufei Cheng
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Yufei Cheng   <yfcheng@ittc.ku.edu>
19
 *
20
 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
 * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
22
 * Information and Telecommunication Technology Center (ITTC)
23
 * and Department of Electrical Engineering and Computer Science
24
 * The University of Kansas Lawrence, KS USA.
25
 *
26
 * Work supported in part by NSF FIND (Future Internet Design) Program
27
 * under grant CNS-0626918 (Postmodern Internet Architecture),
28
 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
 * US Department of Defense (DoD), and ITTC at The University of Kansas.
30
 */
31
32
#include "dsr-passive-buff.h"
33
#include <algorithm>
34
#include <functional>
35
#include "ns3/ipv4-route.h"
36
#include "ns3/socket.h"
37
#include "ns3/log.h"
38
39
NS_LOG_COMPONENT_DEFINE ("PassiveBuffer");
40
41
namespace ns3 {
42
namespace dsr {
43
44
NS_OBJECT_ENSURE_REGISTERED (PassiveBuffer);
45
46
TypeId PassiveBuffer::GetTypeId ()
47
{
48
  static TypeId tid = TypeId ("ns3::dsr::PassiveBuffer")
49
    .SetParent<Object> ()
50
    .AddConstructor<PassiveBuffer> ()
51
  ;
52
  return tid;
53
}
54
55
PassiveBuffer::PassiveBuffer ()
56
{
57
}
58
59
PassiveBuffer::~PassiveBuffer ()
60
{
61
}
62
63
uint32_t
64
PassiveBuffer::GetSize ()
65
{
66
  Purge ();
67
  return m_passiveBuffer.size ();
68
}
69
70
bool
71
PassiveBuffer::Enqueue (PassiveBuffEntry & entry)
72
{
73
  Purge ();
74
  for (std::vector<PassiveBuffEntry>::const_iterator i = m_passiveBuffer.begin (); i
75
       != m_passiveBuffer.end (); ++i)
76
    {
77
      NS_LOG_INFO ("packet id " << i->GetPacket ()->GetUid () << " " << entry.GetPacket ()->GetUid () << " source " << i->GetSource () << " " << entry.GetSource ()
78
                                     << " dst " << i->GetDestination () << " " << entry.GetDestination () << " identification " << i->GetIdentification () << " "
79
                                     << entry.GetIdentification () << " fragment " << i->GetFragmentOffset () << " " << entry.GetFragmentOffset ()
80
                                     << " segLeft " << i->GetSegsLeft () << " " << entry.GetSegsLeft ());
81
82
      if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && (i->GetSource () == entry.GetSource ()) && (i->GetNextHop () == entry.GetNextHop ())
83
          && (i->GetDestination () == entry.GetDestination ()) && (i->GetIdentification () == entry.GetIdentification ()) && (i->GetFragmentOffset () == entry.GetFragmentOffset ())
84
          && (i->GetSegsLeft () == entry.GetSegsLeft () + 1))
85
        {
86
          return false;
87
        }
88
    }
89
90
  entry.SetExpireTime (m_passiveBufferTimeout);     // Initialize the send buffer timeout
91
  /*
92
   * Drop the most aged packet when buffer reaches to max
93
   */
94
  if (m_passiveBuffer.size () >= m_maxLen)
95
    {
96
      Drop (m_passiveBuffer.front (), "Drop the most aged packet");         // Drop the most aged packet
97
      m_passiveBuffer.erase (m_passiveBuffer.begin ());
98
    }
99
  // enqueue the entry
100
  m_passiveBuffer.push_back (entry);
101
  return true;
102
}
103
104
bool
105
PassiveBuffer::AllEqual (PassiveBuffEntry & entry)
106
{
107
  for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i
108
       != m_passiveBuffer.end (); ++i)
109
    {
110
      NS_LOG_INFO ("packet id " << i->GetPacket ()->GetUid () << " " << entry.GetPacket ()->GetUid () << " source " << i->GetSource () << " " << entry.GetSource ()
111
                                     << " dst " << i->GetDestination () << " " << entry.GetDestination () << " identification " << i->GetIdentification () << " "
112
                                     << entry.GetIdentification () << " fragment " << i->GetFragmentOffset () << " " << entry.GetFragmentOffset ()
113
                                     << " segLeft " << (uint32_t) i->GetSegsLeft () << " " << (uint32_t) entry.GetSegsLeft ());
114
115
      if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && (i->GetSource () == entry.GetSource ()) && (i->GetNextHop () == entry.GetNextHop ())
116
          && (i->GetDestination () == entry.GetDestination ()) && (i->GetIdentification () == entry.GetIdentification ()) && (i->GetFragmentOffset () == entry.GetFragmentOffset ())
117
          && (i->GetSegsLeft () == entry.GetSegsLeft () + 1))
118
        {
119
          m_passiveBuffer.erase (i);   // Erase the same maintain buffer entry for the received packet
120
          return true;
121
        }
122
    }
123
  return false;
124
}
125
126
bool
127
PassiveBuffer::Dequeue (Ipv4Address dst, PassiveBuffEntry & entry)
128
{
129
  Purge ();
130
  /*
131
   * Dequeue the entry with destination address dst
132
   */
133
  for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i != m_passiveBuffer.end (); ++i)
134
    {
135
      if (i->GetDestination () == dst)
136
        {
137
          entry = *i;
138
          m_passiveBuffer.erase (i);
139
          NS_LOG_DEBUG ("Packet size while dequeuing " << entry.GetPacket ()->GetSize ());
140
          return true;
141
        }
142
    }
143
  return false;
144
}
145
146
bool
147
PassiveBuffer::Find (Ipv4Address dst)
148
{
149
  /*
150
   * Make sure if the send buffer contains entry with certain dst
151
   */
152
  for (std::vector<PassiveBuffEntry>::const_iterator i = m_passiveBuffer.begin (); i
153
       != m_passiveBuffer.end (); ++i)
154
    {
155
      if (i->GetDestination () == dst)
156
        {
157
          NS_LOG_DEBUG ("Found the packet");
158
          return true;
159
        }
160
    }
161
  return false;
162
}
163
164
struct IsExpired
165
{
166
  bool
167
  operator() (PassiveBuffEntry const & e) const
168
  {
169
    // NS_LOG_DEBUG("Expire time for packet in req queue: "<<e.GetExpireTime ());
170
    return (e.GetExpireTime () < Seconds (0));
171
  }
172
};
173
174
void
175
PassiveBuffer::Purge ()
176
{
177
  /*
178
   * Purge the buffer to eliminate expired entries
179
   */
180
  NS_LOG_DEBUG ("The passive buffer size " << m_passiveBuffer.size ());
181
  IsExpired pred;
182
  for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i
183
       != m_passiveBuffer.end (); ++i)
184
    {
185
      if (pred (*i))
186
        {
187
          NS_LOG_DEBUG ("Dropping Queue Packets");
188
          Drop (*i, "Drop out-dated packet ");
189
        }
190
    }
191
  m_passiveBuffer.erase (std::remove_if (m_passiveBuffer.begin (), m_passiveBuffer.end (), pred),
192
                       m_passiveBuffer.end ());
193
}
194
195
void
196
PassiveBuffer::Drop (PassiveBuffEntry en, std::string reason)
197
{
198
  NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetDestination ());
199
//  en.GetErrorCallback () (en.GetPacket (), en.GetDestination (),
200
//     Socket::ERROR_NOROUTETOHOST);
201
  return;
202
}
203
204
void
205
PassiveBuffer::DropLink (PassiveBuffEntry en, std::string reason)
206
{
207
  NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetSource () << " " << en.GetNextHop ());
208
//  en.GetErrorCallback () (en.GetPacket (), en.GetDestination (),
209
//     Socket::ERROR_NOROUTETOHOST);
210
  return;
211
}
212
}  // namespace dsr
213
}  // namespace ns3
(-)ns3dev/src/dsr/model/dsr-passive-buff.h (+245 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2011 Yufei Cheng
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Yufei Cheng   <yfcheng@ittc.ku.edu>
19
 *
20
 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
 * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
22
 * Information and Telecommunication Technology Center (ITTC)
23
 * and Department of Electrical Engineering and Computer Science
24
 * The University of Kansas Lawrence, KS USA.
25
 *
26
 * Work supported in part by NSF FIND (Future Internet Design) Program
27
 * under grant CNS-0626918 (Postmodern Internet Architecture),
28
 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
 * US Department of Defense (DoD), and ITTC at The University of Kansas.
30
 */
31
32
#ifndef DSR_PASSIVEBUFF_H
33
#define DSR_PASSIVEBUFF_H
34
35
#include <vector>
36
#include "ns3/ipv4-routing-protocol.h"
37
#include "ns3/simulator.h"
38
39
namespace ns3 {
40
namespace dsr {
41
/**
42
 * \ingroup dsr
43
 * \brief DSR Passive Buffer Entry
44
 */
45
class PassiveBuffEntry
46
{
47
public:
48
  // / c-tor
49
  PassiveBuffEntry (Ptr<const Packet> pa = 0, Ipv4Address d = Ipv4Address (), Ipv4Address s = Ipv4Address (),
50
                  Ipv4Address n = Ipv4Address (), uint16_t i = 0, uint16_t f = 0, uint8_t seg = 0, Time exp = Simulator::Now (),
51
                  uint8_t p = 0)
52
    : m_packet (pa),
53
      m_dst (d),
54
      m_source (s),
55
      m_nextHop (n),
56
      m_identification (i),
57
      m_fragmentOffset (f),
58
      m_segsLeft (seg),
59
      m_expire (exp + Simulator::Now ()),
60
      m_protocol (p)
61
  {
62
  }
63
  /**
64
   * Compare send buffer entries
65
   * \return true if equal
66
   */
67
  bool operator== (PassiveBuffEntry const & o) const
68
  {
69
    return ((m_packet == o.m_packet) && (m_source == o.m_source) && (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
70
  }
71
  // /\name Fields
72
  // \{
73
  Ptr<const Packet> GetPacket () const
74
  {
75
    return m_packet;
76
  }
77
  void SetPacket (Ptr<const Packet> p)
78
  {
79
    m_packet = p;
80
  }
81
  Ipv4Address GetDestination () const
82
  {
83
    return m_dst;
84
  }
85
  void SetDestination (Ipv4Address d)
86
  {
87
    m_dst = d;
88
  }
89
  Ipv4Address GetSource () const
90
  {
91
    return m_source;
92
  }
93
  void SetSource (Ipv4Address s)
94
  {
95
    m_source = s;
96
  }
97
  Ipv4Address GetNextHop () const
98
  {
99
    return m_nextHop;
100
  }
101
  void SetNextHop (Ipv4Address n)
102
  {
103
    m_nextHop = n;
104
  }
105
  uint16_t GetIdentification () const
106
  {
107
    return m_identification;
108
  }
109
  void SetIdentification (uint16_t i)
110
  {
111
    m_identification = i;
112
  }
113
  uint16_t GetFragmentOffset () const
114
  {
115
    return m_fragmentOffset;
116
  }
117
  void SetFragmentOffset (uint16_t f)
118
  {
119
    m_fragmentOffset = f;
120
  }
121
  uint8_t GetSegsLeft () const
122
  {
123
    return m_segsLeft;
124
  }
125
  void SetSegsLeft (uint8_t seg)
126
  {
127
    m_segsLeft = seg;
128
  }
129
  void SetExpireTime (Time exp)
130
  {
131
    m_expire = exp + Simulator::Now ();
132
  }
133
  Time GetExpireTime () const
134
  {
135
    return m_expire - Simulator::Now ();
136
  }
137
  void SetProtocol (uint8_t p)
138
  {
139
    m_protocol = p;
140
  }
141
  uint8_t GetProtocol () const
142
  {
143
    return m_protocol;
144
  }
145
  // \}
146
private:
147
  // / Data packet
148
  Ptr<const Packet> m_packet;
149
  // / Destination address
150
  Ipv4Address m_dst;
151
  // / Source address
152
  Ipv4Address m_source;
153
  // / Nexthop address
154
  Ipv4Address m_nextHop;
155
  // /
156
  uint16_t m_identification;
157
  uint16_t m_fragmentOffset;
158
  uint8_t m_segsLeft;
159
  // / Expire time for queue entry
160
  Time m_expire;
161
  // / The protocol number
162
  uint8_t m_protocol;
163
};
164
165
/**
166
 * \ingroup dsr
167
 * \brief DSR passive buffer
168
 */
169
/************************************************************************************************************************/
170
class PassiveBuffer  : public Object
171
{
172
public:
173
  // / c-tor
174
  /**
175
   * \brief Get the type identificator.
176
   * \return type identificator
177
   */
178
  static TypeId GetTypeId ();
179
  /**
180
   * \brief Constructor.
181
   */
182
  PassiveBuffer ();
183
  /**
184
   * \brief Destructor.
185
   */
186
  virtual ~PassiveBuffer ();
187
  // / Push entry in queue, if there is no entry with the same packet and destination address in queue.
188
  bool Enqueue (PassiveBuffEntry & entry);
189
  // / Return first found (the earliest) entry for given destination
190
  bool Dequeue (Ipv4Address dst, PassiveBuffEntry & entry);
191
  // / Finds whether a packet with destination dst exists in the queue
192
  bool Find (Ipv4Address dst);
193
  // / Check if all the entries in passive buffer entry is all equal or not
194
  bool AllEqual (PassiveBuffEntry & entry);
195
  // / Number of entries
196
  uint32_t GetSize ();
197
  // /\name Fields
198
  // \{
199
  uint32_t GetMaxQueueLen () const
200
  {
201
    return m_maxLen;
202
  }
203
  void SetMaxQueueLen (uint32_t len)
204
  {
205
    m_maxLen = len;
206
  }
207
  Time GetPassiveBufferTimeout () const
208
  {
209
    return m_passiveBufferTimeout;
210
  }
211
  void SetPassiveBufferTimeout (Time t)
212
  {
213
    m_passiveBufferTimeout = t;
214
  }
215
  // \}
216
217
  std::vector<PassiveBuffEntry> & GetBuffer ()     /// TODO may need to remove this one here
218
  {
219
    return m_passiveBuffer;
220
  }
221
222
private:
223
  // / The send buffer to cache unsent packet
224
  std::vector<PassiveBuffEntry> m_passiveBuffer;
225
  // / Remove all expired entries
226
  void Purge ();
227
  // / Notify that packet is dropped from queue by timeout
228
  void Drop (PassiveBuffEntry en, std::string reason);
229
  // / Notify that packet is dropped from queue by timeout
230
  void DropLink (PassiveBuffEntry en, std::string reason);
231
  // / The maximum number of packets that we allow a routing protocol to buffer.
232
  uint32_t m_maxLen;
233
  // / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
234
  Time m_passiveBufferTimeout;
235
  // / Check if the send buffer entry is the same or not
236
  static bool LinkEqual (PassiveBuffEntry en, const std::vector<Ipv4Address> link)
237
  {
238
    return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
239
  }
240
};
241
/*******************************************************************************************************************************/
242
} // namespace dsr
243
} // namespace ns3
244
245
#endif /* DSR_PASSIVEBUFF_H */
(-)ns3dev/src/dsr/model/dsr-routing.cc (-19 / +118 lines)
 Lines 113-118   TypeId DsrRouting::GetTypeId () Link Here 
113
                   MakePointerAccessor (&DsrRouting::SetRequestTable,
113
                   MakePointerAccessor (&DsrRouting::SetRequestTable,
114
                                        &DsrRouting::GetRequestTable),
114
                                        &DsrRouting::GetRequestTable),
115
                   MakePointerChecker<RreqTable> ())
115
                   MakePointerChecker<RreqTable> ())
116
    .AddAttribute ("PassiveBuffer", "The passive buffer to manage promisucously received passive ack.",
117
                   PointerValue (0),
118
                   MakePointerAccessor (&DsrRouting::SetPassiveBuffer,
119
                                        &DsrRouting::GetPassiveBuffer),
120
                   MakePointerChecker<PassiveBuffer> ())
116
    .AddAttribute ("MaxSendBuffLen","Maximum number of packets that can be stored in send buffer.",
121
    .AddAttribute ("MaxSendBuffLen","Maximum number of packets that can be stored in send buffer.",
117
                   UintegerValue (64),
122
                   UintegerValue (64),
118
                   MakeUintegerAccessor (&DsrRouting::m_maxSendBuffLen),
123
                   MakeUintegerAccessor (&DsrRouting::m_maxSendBuffLen),
 Lines 154-162   TypeId DsrRouting::GetTypeId () Link Here 
154
                   MakeUintegerAccessor (&DsrRouting::m_rreqRetries),
159
                   MakeUintegerAccessor (&DsrRouting::m_rreqRetries),
155
                   MakeUintegerChecker<uint32_t> ())
160
                   MakeUintegerChecker<uint32_t> ())
156
    .AddAttribute ("MaintenanceRetries","Maximum number of retransmissions for data packets from maintenance buffer.",
161
    .AddAttribute ("MaintenanceRetries","Maximum number of retransmissions for data packets from maintenance buffer.",
157
                   DoubleValue (2),
162
                   UintegerValue (2),
158
                   MakeDoubleAccessor (&DsrRouting::m_maxMaintRexmt),
163
                   MakeUintegerAccessor (&DsrRouting::m_maxMaintRexmt),
159
                   MakeDoubleChecker<uint32_t> ())
164
                   MakeUintegerChecker<uint32_t> ())
160
    .AddAttribute ("RequestTableSize","Maximum number of request entries in the request table.",
165
    .AddAttribute ("RequestTableSize","Maximum number of request entries in the request table.",
161
                   UintegerValue (64),
166
                   UintegerValue (64),
162
                   MakeUintegerAccessor (&DsrRouting::m_requestTableSize),
167
                   MakeUintegerAccessor (&DsrRouting::m_requestTableSize),
 Lines 174-182   TypeId DsrRouting::GetTypeId () Link Here 
174
                   MakeTimeAccessor (&DsrRouting::m_nonpropRequestTimeout),
179
                   MakeTimeAccessor (&DsrRouting::m_nonpropRequestTimeout),
175
                   MakeTimeChecker ())
180
                   MakeTimeChecker ())
176
    .AddAttribute ("DiscoveryHopLimit","The max discovery hop limit for route requests.",
181
    .AddAttribute ("DiscoveryHopLimit","The max discovery hop limit for route requests.",
177
                   DoubleValue (255),
182
                   UintegerValue (255),
178
                   MakeDoubleAccessor (&DsrRouting::m_discoveryHopLimit),
183
                   MakeUintegerAccessor (&DsrRouting::m_discoveryHopLimit),
179
                   MakeDoubleChecker<uint32_t> ())
184
                   MakeUintegerChecker<uint32_t> ())
180
    .AddAttribute ("MaxSalvageCount","The max salvage count for a single data packet.",
185
    .AddAttribute ("MaxSalvageCount","The max salvage count for a single data packet.",
181
                   UintegerValue (15),
186
                   UintegerValue (15),
182
                   MakeUintegerAccessor (&DsrRouting::m_maxSalvageCount),
187
                   MakeUintegerAccessor (&DsrRouting::m_maxSalvageCount),
 Lines 353-358   void DsrRouting::Start () Link Here 
353
  // The call back to handle link error and send error message to appropriate nodes
358
  // The call back to handle link error and send error message to appropriate nodes
354
  routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkToNextHop, this));
359
  routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkToNextHop, this));
355
  SetRouteCache (routeCache);
360
  SetRouteCache (routeCache);
361
// Set the passive buffer parameters using just the send buffer parameters
362
  Ptr<dsr::PassiveBuffer> passiveBuffer = CreateObject<dsr::PassiveBuffer> ();
363
  passiveBuffer->SetMaxQueueLen (m_maxSendBuffLen);
364
  passiveBuffer->SetPassiveBufferTimeout (m_sendBufferTimeout);
365
  SetPassiveBuffer (passiveBuffer);
356
366
357
  if (m_mainAddress == Ipv4Address ())
367
  if (m_mainAddress == Ipv4Address ())
358
    {
368
    {
 Lines 486-491   DsrRouting::GetRequestTable () const Link Here 
486
  return m_rreqTable;
496
  return m_rreqTable;
487
}
497
}
488
498
499
void DsrRouting::SetPassiveBuffer (Ptr<dsr::PassiveBuffer> p)
500
{
501
  // / Set the request table to use
502
  m_passiveBuffer = p;
503
}
504
505
Ptr<dsr::PassiveBuffer>
506
DsrRouting::GetPassiveBuffer () const
507
{
508
  // / Get the request table to use
509
  return m_passiveBuffer;
510
}
511
489
bool DsrRouting::IsLinkCache ()
512
bool DsrRouting::IsLinkCache ()
490
{
513
{
491
  return m_routeCache->IsLinkCache ();
514
  return m_routeCache->IsLinkCache ();
 Lines 526-531   bool DsrRouting::UpdateRouteEntry (Ipv4A Link Here 
526
  return m_routeCache->UpdateRouteEntry (dst);
549
  return m_routeCache->UpdateRouteEntry (dst);
527
}
550
}
528
551
552
bool DsrRouting::FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t id)
553
{
554
  return m_rreqTable->FindSourceEntry (src, dst, id);
555
}
556
529
Ipv4Address
557
Ipv4Address
530
DsrRouting::GetIPfromMAC (Mac48Address address)
558
DsrRouting::GetIPfromMAC (Mac48Address address)
531
{
559
{
 Lines 704-710   void DsrRouting::SendRerrWhenBreaksLinkT Link Here 
704
          newPacket->RemoveHeader (sourceRoute);
732
          newPacket->RemoveHeader (sourceRoute);
705
          uint8_t salvage = sourceRoute.GetSalvage ();
733
          uint8_t salvage = sourceRoute.GetSalvage ();
706
734
707
          // TODO
708
          DsrOptionAckReqHeader ackReq;
735
          DsrOptionAckReqHeader ackReq;
709
          newPacket->RemoveHeader (ackReq);
736
          newPacket->RemoveHeader (ackReq);
710
          /*
737
          /*
 Lines 1032-1051   bool DsrRouting::PromiscReceive (Ptr<Net Link Here 
1032
          optionType = *(data);
1059
          optionType = *(data);
1033
1060
1034
          Ptr<dsr::DsrOptions> dsrOption;
1061
          Ptr<dsr::DsrOptions> dsrOption;
1035
1062
          Ipv4Address promiscSource = GetIPfromMAC (Mac48Address::ConvertFrom (from));
1063
          Ipv4Address promiscDestination = GetIPfromMAC (Mac48Address::ConvertFrom (to));
1036
          if (optionType == 96)        // This is the source route option
1064
          if (optionType == 96)        // This is the source route option
1037
            {
1065
            {
1038
              dsrOption = GetOption (optionType);       // Get the relative DSR option and demux to the process function
1066
              dsrOption = GetOption (optionType);       // Get the relative DSR option and demux to the process function
1039
              NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << 
1067
              NS_LOG_DEBUG (Simulator::Now ().GetSeconds () <<
1040
                            " DSR node " << m_mainAddress <<
1068
                            " DSR node " << m_mainAddress <<
1041
                            " overhearing packet PID: " << p->GetUid () <<
1069
                            " overhearing packet PID: " << p->GetUid () <<
1042
                            " from " << GetIPfromMAC (Mac48Address::ConvertFrom (from)) <<
1070
                            " from " << promiscSource <<
1043
                            " to " << GetIPfromMAC (Mac48Address::ConvertFrom (to)) <<
1071
                            " to " << promiscDestination <<
1044
                            " with source IP " << ipv4Header.GetSource () <<
1072
                            " with source IP " << ipv4Header.GetSource () <<
1045
                            " and destination IP " << ipv4Header.GetDestination () <<
1073
                            " and destination IP " << ipv4Header.GetDestination () <<
1046
                            " and packet : " << *dsrPacket);
1074
                            " and packet : " << *dsrPacket);
1047
              bool isPromisc = true;                     // Set the boolean value isPromisc as true
1075
              bool isPromisc = true;                     // Set the boolean value isPromisc as true
1048
              dsrOption->Process (p, dsrPacket, m_mainAddress, source, ipv4Header, nextHeader, isPromisc);
1076
1077
              dsrOption->Process (p, dsrPacket, m_mainAddress, source, ipv4Header, nextHeader, isPromisc, promiscSource);
1049
              return true;
1078
              return true;
1050
            }
1079
            }
1051
        }
1080
        }
 Lines 1797-1802   DsrRouting::SendPacketFromBuffer (DsrOpt Link Here 
1797
}
1826
}
1798
1827
1799
bool
1828
bool
1829
DsrRouting::PassiveEntryCheck (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft,
1830
                    uint16_t fragmentOffset, uint16_t identification, bool saveEntry)
1831
{
1832
  NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)segsLeft);
1833
1834
  Ptr<Packet> p = packet->Copy ();
1835
  // Here the segments left value need to plus one to check the earlier hop maintain buffer entry
1836
  PassiveBuffEntry newEntry;
1837
  newEntry.SetPacket (p);
1838
  newEntry.SetSource (source);
1839
  newEntry.SetDestination (destination);
1840
  newEntry.SetIdentification (identification);
1841
  newEntry.SetFragmentOffset (fragmentOffset);
1842
  newEntry.SetSegsLeft (segsLeft);  // We try to make sure the segments left is larger for 1
1843
1844
  NS_LOG_DEBUG ("The passive buffer size " << m_passiveBuffer->GetSize());
1845
1846
  if (m_passiveBuffer->AllEqual (newEntry) && (!saveEntry))
1847
    {
1848
      // The PromiscEqual function will remove the maintain buffer entry if equal value found
1849
      // It only compares the source and destination address, ackId, and the segments left value
1850
      NS_LOG_DEBUG ("We get the all equal for passive buffer here");
1851
1852
      MaintainBuffEntry mbEntry;
1853
      mbEntry.SetPacket (p);
1854
      mbEntry.SetSrc (source);
1855
      mbEntry.SetDst (destination);
1856
      mbEntry.SetAckId (0);
1857
      mbEntry.SetSegsLeft (segsLeft + 1);
1858
1859
    /// TODO this needs to be done later
1860
      CancelPassivePacketTimer (mbEntry);
1861
      return true;
1862
    }
1863
  if (saveEntry)
1864
    {
1865
      /// Save this passive buffer entry for later check
1866
      m_passiveBuffer->Enqueue (newEntry);
1867
    }
1868
  return false;
1869
}
1870
1871
bool
1872
DsrRouting::CancelPassiveTimer (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination,
1873
                                 uint8_t segsLeft)
1874
{
1875
  NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)segsLeft);
1876
1877
  NS_LOG_DEBUG ("Cancel the passive timer");
1878
1879
  Ptr<Packet> p = packet->Copy ();
1880
  // Here the segments left value need to plus one to check the earlier hop maintain buffer entry
1881
  MaintainBuffEntry newEntry;
1882
  newEntry.SetPacket (p);
1883
  newEntry.SetSrc (source);
1884
  newEntry.SetDst (destination);
1885
  newEntry.SetAckId (0);
1886
  newEntry.SetSegsLeft (segsLeft + 1);
1887
1888
  if (m_maintainBuffer.PromiscEqual (newEntry))
1889
    {
1890
      // The PromiscEqual function will remove the maintain buffer entry if equal value found
1891
      // It only compares the source and destination address, ackId, and the segments left value
1892
      CancelPassivePacketTimer (newEntry);
1893
      return true;
1894
    }
1895
  return false;
1896
}
1897
1898
bool
1800
DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination,
1899
DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination,
1801
                             uint8_t segsLeft)
1900
                             uint8_t segsLeft)
1802
{
1901
{
 Lines 2632-2638   DsrRouting::ScheduleRreqRetry (Ptr<Packe Link Here 
2632
          NS_LOG_DEBUG ("The request delay time " << rreqDelay.GetSeconds ());
2731
          NS_LOG_DEBUG ("The request delay time " << rreqDelay.GetSeconds ());
2633
          m_addressReqTimer[dst].Schedule (rreqDelay);
2732
          m_addressReqTimer[dst].Schedule (rreqDelay);
2634
        }
2733
        }
2635
2636
    }
2734
    }
2637
}
2735
}
2638
2736
 Lines 2956-2962   DsrRouting::Receive (Ptr<Packet> p, Link Here 
2956
  optionType = *(data);
3054
  optionType = *(data);
2957
  NS_LOG_LOGIC ("The option type value " << (uint32_t)optionType << " with packet size " << p->GetSize ());
3055
  NS_LOG_LOGIC ("The option type value " << (uint32_t)optionType << " with packet size " << p->GetSize ());
2958
  dsrOption = GetOption (optionType);       // Get the relative dsr option and demux to the process function
3056
  dsrOption = GetOption (optionType);       // Get the relative dsr option and demux to the process function
2959
3057
  // This promisc source is just set as empty, only the promisc received packet will have a promisc source value
3058
  Ipv4Address promiscSource;
2960
  if (optionType == 1)        // This is the request option
3059
  if (optionType == 1)        // This is the request option
2961
    {
3060
    {
2962
      BlackList *blackList = m_rreqTable->FindUnidirectional (src);
3061
      BlackList *blackList = m_rreqTable->FindUnidirectional (src);
 Lines 2967-2973   DsrRouting::Receive (Ptr<Packet> p, Link Here 
2967
        }
3066
        }
2968
3067
2969
      dsrOption = GetOption (optionType);
3068
      dsrOption = GetOption (optionType);
2970
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
3069
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
2971
3070
2972
      if (optionLength == 0)
3071
      if (optionLength == 0)
2973
        {
3072
        {
 Lines 2978-2984   DsrRouting::Receive (Ptr<Packet> p, Link Here 
2978
  else if (optionType == 2)
3077
  else if (optionType == 2)
2979
    {
3078
    {
2980
      dsrOption = GetOption (optionType);
3079
      dsrOption = GetOption (optionType);
2981
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
3080
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
2982
3081
2983
      if (optionLength == 0)
3082
      if (optionLength == 0)
2984
        {
3083
        {
 Lines 2991-2997   DsrRouting::Receive (Ptr<Packet> p, Link Here 
2991
    {
3090
    {
2992
      NS_LOG_DEBUG ("This is the ack option");
3091
      NS_LOG_DEBUG ("This is the ack option");
2993
      dsrOption = GetOption (optionType);
3092
      dsrOption = GetOption (optionType);
2994
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
3093
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
2995
3094
2996
      if (optionLength == 0)
3095
      if (optionLength == 0)
2997
        {
3096
        {
 Lines 3006-3012   DsrRouting::Receive (Ptr<Packet> p, Link Here 
3006
      NS_LOG_DEBUG ("The option type value " << (uint32_t)optionType);
3105
      NS_LOG_DEBUG ("The option type value " << (uint32_t)optionType);
3007
3106
3008
      dsrOption = GetOption (optionType);
3107
      dsrOption = GetOption (optionType);
3009
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
3108
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3010
3109
3011
      if (optionLength == 0)
3110
      if (optionLength == 0)
3012
        {
3111
        {
 Lines 3020-3026   DsrRouting::Receive (Ptr<Packet> p, Link Here 
3020
    {
3119
    {
3021
      NS_LOG_DEBUG ("This is the source route option " << (uint32_t)optionType);
3120
      NS_LOG_DEBUG ("This is the source route option " << (uint32_t)optionType);
3022
      dsrOption = GetOption (optionType);
3121
      dsrOption = GetOption (optionType);
3023
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
3122
      optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3024
3123
3025
      segmentsLeft = *(data + 3);
3124
      segmentsLeft = *(data + 3);
3026
      NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)segmentsLeft);
3125
      NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)segmentsLeft);
(-)ns3dev/src/dsr/model/dsr-routing.h (-1 / +24 lines)
 Lines 67-72    Link Here 
67
#include "dsr-rcache.h"
67
#include "dsr-rcache.h"
68
#include "dsr-rreq-table.h"
68
#include "dsr-rreq-table.h"
69
#include "dsr-maintain-buff.h"
69
#include "dsr-maintain-buff.h"
70
#include "dsr-passive-buff.h"
70
#include "dsr-option-header.h"
71
#include "dsr-option-header.h"
71
#include "dsr-fs-header.h"
72
#include "dsr-fs-header.h"
72
#include "dsr-rsendbuff.h"
73
#include "dsr-rsendbuff.h"
 Lines 141-146   public: Link Here 
141
    * \return the request table
142
    * \return the request table
142
    */
143
    */
143
  Ptr<dsr::RreqTable> GetRequestTable () const;
144
  Ptr<dsr::RreqTable> GetRequestTable () const;
145
  /**
146
   * \brief Set the node.
147
   * \param the passive buffer to set
148
   */
149
  void SetPassiveBuffer (Ptr<dsr::PassiveBuffer> r);
150
  /**
151
    * \brief Get the passive buffer
152
    * \return the passive buffer
153
    */
154
  Ptr<dsr::PassiveBuffer> GetPassiveBuffer () const;
144
155
145
  ///\functions used to direct to route cache
156
  ///\functions used to direct to route cache
146
  //\{
157
  //\{
 Lines 151-156   public: Link Here 
151
  bool AddRoute (RouteCacheEntry & rt);
162
  bool AddRoute (RouteCacheEntry & rt);
152
  void DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node);
163
  void DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node);
153
  bool UpdateRouteEntry (Ipv4Address dst);
164
  bool UpdateRouteEntry (Ipv4Address dst);
165
  bool FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t id);
154
  //\}
166
  //\}
155
167
156
  /**
168
  /**
 Lines 256-261   public: Link Here 
256
  void SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute,
268
  void SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute,
257
                             Ipv4Address nextHop,
269
                             Ipv4Address nextHop,
258
                             uint8_t protocol);
270
                             uint8_t protocol);
271
  /**
272
   * \brief Find the same passive entry
273
   */
274
  bool PassiveEntryCheck (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft,
275
                      uint16_t fragmentOffset, uint16_t identification, bool saveEntry);
276
  /**
277
   * \brief Cancel the passive timer
278
   */
279
  bool CancelPassiveTimer (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft);
259
  /*
280
  /*
260
   * \brief Find the similar entries in the maintenance buffer
281
   * \brief Find the similar entries in the maintenance buffer
261
   */
282
   */
 Lines 616-621   private: Link Here 
616
637
617
  Ptr<dsr::RreqTable> m_rreqTable;        // / A "drop-front" queue used by the routing layer to cache route request sent.
638
  Ptr<dsr::RreqTable> m_rreqTable;        // / A "drop-front" queue used by the routing layer to cache route request sent.
618
639
640
  Ptr<dsr::PassiveBuffer> m_passiveBuffer;              ///< A "drop-front" queue used by the routing layer to cache route request sent.
641
619
  uint32_t m_numPriorityQueues;
642
  uint32_t m_numPriorityQueues;
620
643
621
  std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> > m_priorityQueue;   // / priority queueus
644
  std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> > m_priorityQueue;   // / priority queueus
 Lines 627-633   private: Link Here 
627
  std::vector<Ipv4Address> m_addresses;   // / The bind ipv4 addresses with next hop, src, destination address in sequence
650
  std::vector<Ipv4Address> m_addresses;   // / The bind ipv4 addresses with next hop, src, destination address in sequence
628
651
629
  /// Provides uniform random variables.
652
  /// Provides uniform random variables.
630
  Ptr<UniformRandomVariable> m_uniformRandomVariable;  
653
  Ptr<UniformRandomVariable> m_uniformRandomVariable;
631
};
654
};
632
}  /* namespace dsr */
655
}  /* namespace dsr */
633
}  /* namespace ns3 */
656
}  /* namespace ns3 */
(-)ns3dev/src/dsr/model/dsr-rreq-table.cc (-14 / +61 lines)
 Lines 88-101   RreqTable::FindAndUpdate (Ipv4Address ds Link Here 
88
    m_rreqDstMap.find (dst);
88
    m_rreqDstMap.find (dst);
89
  if (i == m_rreqDstMap.end ())
89
  if (i == m_rreqDstMap.end ())
90
    {
90
    {
91
      NS_LOG_DEBUG ("The request table entry for " << dst << " not found");
91
      NS_LOG_LOGIC ("The request table entry for " << dst << " not found");
92
      /*
92
      /*
93
       * Drop the most aged packet when buffer reaches to max
93
       * Drop the most aged packet when buffer reaches to max
94
       */
94
       */
95
      if (m_rreqDstMap.size () >= m_requestTableSize)
95
      if (m_rreqDstMap.size () >= m_requestTableSize)
96
        {
96
        {
97
          RemoveLeastExpire (m_rreqDstMap);
97
          RemoveLeastExpire (m_rreqDstMap);
98
          NS_LOG_DEBUG ("The request table size after erase " << (uint32_t)m_rreqDstMap.size ());
98
          NS_LOG_INFO ("The request table size after erase " << (uint32_t)m_rreqDstMap.size ());
99
        }
99
        }
100
      RreqTableEntry rreqTableEntry;
100
      RreqTableEntry rreqTableEntry;
101
      rreqTableEntry.m_reqNo = 1;
101
      rreqTableEntry.m_reqNo = 1;
 Lines 104-114   RreqTable::FindAndUpdate (Ipv4Address ds Link Here 
104
    }
104
    }
105
  else
105
  else
106
    {
106
    {
107
      NS_LOG_INFO ("Find the request table entry for  " << dst << ", increment the request count");
107
      NS_LOG_LOGIC ("Find the request table entry for  " << dst << ", increment the request count");
108
      Ipv4Address dst = i->first;
108
      Ipv4Address dst = i->first;
109
      RreqTableEntry rreqTableEntry = i->second;
109
      RreqTableEntry rreqTableEntry = i->second;
110
      NS_LOG_DEBUG ("The request count before incrementing " << rreqTableEntry.m_reqNo);
110
      rreqTableEntry.m_reqNo = rreqTableEntry.m_reqNo + 1;
111
      rreqTableEntry.m_reqNo = (rreqTableEntry.m_reqNo + 1);
112
      rreqTableEntry.m_expire = Simulator::Now ();
111
      rreqTableEntry.m_expire = Simulator::Now ();
113
      m_rreqDstMap [dst] = rreqTableEntry;
112
      m_rreqDstMap [dst] = rreqTableEntry;
114
    }
113
    }
 Lines 118-129   void Link Here 
118
RreqTable::RemoveRreqEntry (Ipv4Address dst)
117
RreqTable::RemoveRreqEntry (Ipv4Address dst)
119
{
118
{
120
  NS_LOG_FUNCTION (this << dst);
119
  NS_LOG_FUNCTION (this << dst);
121
  NS_LOG_DEBUG ("Remove rreq entry with index dst");
122
  std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
120
  std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
123
    m_rreqDstMap.find (dst);
121
    m_rreqDstMap.find (dst);
124
  if (i == m_rreqDstMap.end ())
122
  if (i == m_rreqDstMap.end ())
125
    {
123
    {
126
      NS_LOG_DEBUG ("The request table entry not found");
124
      NS_LOG_LOGIC ("The request table entry not found");
127
    }
125
    }
128
  else
126
  else
129
    {
127
    {
 Lines 140-170   RreqTable::GetRreqCnt (Ipv4Address dst) Link Here 
140
    m_rreqDstMap.find (dst);
138
    m_rreqDstMap.find (dst);
141
  if (i == m_rreqDstMap.end ())
139
  if (i == m_rreqDstMap.end ())
142
    {
140
    {
143
      NS_LOG_DEBUG ("The request table entry not found");
141
      NS_LOG_LOGIC ("Request table entry not found");
144
      return 0;
142
      return 0;
145
    }
143
    }
146
  else
144
  else
147
    {
145
    {
148
      RreqTableEntry rreqTableEntry = i->second;
146
      RreqTableEntry rreqTableEntry = i->second;
149
      NS_LOG_DEBUG ("Find the request count for " << dst << " " << rreqTableEntry.m_reqNo);
150
      return rreqTableEntry.m_reqNo;
147
      return rreqTableEntry.m_reqNo;
151
    }
148
    }
152
}
149
}
153
150
154
// ----------------------------------------------------------------------------------------------------------
151
// ----------------------------------------------------------------------------------------------------------
155
/**
152
/*
156
 * This part takes care of the route request ID initialized from a specific source to one destination
153
 * This part takes care of the route request ID initialized from a specific source to one destination
157
 * Essentially a counter
154
 * Essentially a counter
158
 */
155
 */
159
uint32_t
156
uint32_t
160
RreqTable::CheckUniqueRreqId (Ipv4Address dst)
157
RreqTable::CheckUniqueRreqId (Ipv4Address dst)
161
{
158
{
162
  NS_LOG_DEBUG ("The size of id cache " << m_rreqIdCache.size ());
159
  NS_LOG_LOGIC ("The size of id cache " << m_rreqIdCache.size ());
163
  std::map<Ipv4Address, uint32_t>::const_iterator i =
160
  std::map<Ipv4Address, uint32_t>::const_iterator i =
164
    m_rreqIdCache.find (dst);
161
    m_rreqIdCache.find (dst);
165
  if (i == m_rreqIdCache.end ())
162
  if (i == m_rreqIdCache.end ())
166
    {
163
    {
167
      NS_LOG_LOGIC ("No Request id for " << dst << " found");
164
      NS_LOG_LOGIC ("No Request id for " << dst << " found, initialize it to 0");
168
      m_rreqIdCache[dst] = 0;
165
      m_rreqIdCache[dst] = 0;
169
      return 0;
166
      return 0;
170
    }
167
    }
 Lines 183-189   RreqTable::CheckUniqueRreqId (Ipv4Addres Link Here 
183
          rreqId++;
180
          rreqId++;
184
          m_rreqIdCache[dst] = rreqId;
181
          m_rreqIdCache[dst] = rreqId;
185
        }
182
        }
186
      NS_LOG_DEBUG ("The Request id for " << dst << " is " << rreqId);
183
      NS_LOG_INFO ("The Request id for " << dst << " is " << rreqId);
187
      return rreqId;
184
      return rreqId;
188
    }
185
    }
189
}
186
}
 Lines 195-201   RreqTable::GetRreqSize () Link Here 
195
}
192
}
196
193
197
// ----------------------------------------------------------------------------------------------------------
194
// ----------------------------------------------------------------------------------------------------------
198
/**
195
/*
199
 * This part takes care of black list which can save unidirectional link information
196
 * This part takes care of black list which can save unidirectional link information
200
 */
197
 */
201
198
 Lines 253-257   RreqTable::PurgeNeighbor () Link Here 
253
                                IsExpired ()), m_blackList.end ());
250
                                IsExpired ()), m_blackList.end ());
254
}
251
}
255
252
253
bool
254
RreqTable::FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t id)
255
{
256
  NS_LOG_FUNCTION (this << src << dst << id);
257
  ReceivedRreqEntry rreqEntry;
258
  rreqEntry.SetDestination (dst);
259
  rreqEntry.SetIdentification (id);
260
  std::list<ReceivedRreqEntry> receivedRreqEntryList;
261
  /*
262
   * this function will return false if the entry is not found, true if duplicate entry find
263
   */
264
  std::map<Ipv4Address, std::list<ReceivedRreqEntry> >::const_iterator i = m_sourceRreqMap.find (src);
265
  if (i == m_sourceRreqMap.end ())
266
    {
267
      NS_LOG_LOGIC ("The source request table entry for " << src << " not found");
268
269
      receivedRreqEntryList.clear ();  /// Clear the received source request entry
270
      receivedRreqEntryList.push_back (rreqEntry);
271
272
      m_sourceRreqMap [src] = receivedRreqEntryList;
273
      return false;
274
    }
275
  else
276
    {
277
      NS_LOG_LOGIC ("Find the request table entry for  " << src << ", check if it is exact duplicate");
278
      /*
279
       * Drop the most aged packet when buffer reaches to max
280
       */
281
      receivedRreqEntryList = i->second;
282
      if (receivedRreqEntryList.size () >= m_requestIdSize)
283
        {
284
          receivedRreqEntryList.pop_front ();
285
        }
286
      Ipv4Address src = i->first;
287
      // We loop the receive rreq entry to find duplicate
288
      for (std::list<ReceivedRreqEntry>::const_iterator j = receivedRreqEntryList.begin (); j != receivedRreqEntryList.end (); ++j)
289
        {
290
          ReceivedRreqEntry newEntry = *j;
291
          if (*j == rreqEntry)          /// Check if we have found one duplication entry or not
292
            {
293
              return true;
294
            }
295
        }
296
      /// if this entry is not found, we need to save the entry in the cache, and then return false for the check
297
      receivedRreqEntryList.push_back (rreqEntry);
298
      m_sourceRreqMap [src] = receivedRreqEntryList;
299
      return false;
300
    }
301
}
302
256
} // namespace dsr
303
} // namespace dsr
257
} // namespace ns3
304
} // namespace ns3
(-)ns3dev/src/dsr/model/dsr-rreq-table.h (-17 / +76 lines)
 Lines 62-68   struct BlackList Link Here 
62
  {
62
  {
63
  }
63
  }
64
};
64
};
65
/*
65
/**
66
 * The route request table entries
66
 * The route request table entries
67
 */
67
 */
68
struct RreqTableEntry
68
struct RreqTableEntry
 Lines 71-86   struct RreqTableEntry Link Here 
71
  Time m_expire;
71
  Time m_expire;
72
};
72
};
73
/*
73
/*
74
 * The route request table id for originators
74
 * The request entry for intermediate nodes to check if they have received this request or not
75
 * It is responsible for checking duplicate requests from a single source to a specific destination
75
 * This is used to control the duplication request from being processed
76
 */
76
 */
77
struct SourceRreqEntry
77
class ReceivedRreqEntry
78
{
78
{
79
  uint32_t m_identification;
79
public:
80
  Ipv4Address m_dst;
80
  // / c-tor
81
  bool m_isError;
81
  ReceivedRreqEntry (Ipv4Address d = Ipv4Address (), uint16_t i = 0)
82
  Time m_expire;
82
    : m_destination (d),
83
      m_identification (i)
84
  {
85
  }
86
  /**
87
   * Compare send buffer entries
88
   * \return true if equal
89
   */
90
  bool operator== (ReceivedRreqEntry const & o) const
91
  {
92
    return ((m_destination == o.m_destination) && (m_identification == o.m_identification)
93
           );
94
  }
95
  // /\name Fields
96
  // \{
97
  Ipv4Address GetDestination () const
98
  {
99
    return m_destination;
100
  }
101
  void SetDestination (Ipv4Address d)
102
  {
103
    m_destination = d;
104
  }
105
  Ipv4Address GetSource () const
106
  {
107
    return m_source;
108
  }
109
  void SetSource (Ipv4Address s)
110
  {
111
    m_source = s;
112
  }
113
  uint16_t GetIdentification () const
114
  {
115
    return m_identification;
116
  }
117
  void SetIdentification (uint16_t i)
118
  {
119
    m_identification = i;
120
  }
121
  void SetExpireTime (Time exp)
122
  {
123
    m_expire = exp + Simulator::Now ();
124
  }
125
  Time GetExpireTime () const
126
  {
127
    return m_expire - Simulator::Now ();
128
  }
129
  // \}
130
private:
131
    Ipv4Address m_destination;
132
    Ipv4Address m_source;
133
    uint16_t m_identification;
134
    Time m_expire;
83
};
135
};
136
84
/**
137
/**
85
 * \ingroup dsr
138
 * \ingroup dsr
86
 * \brief maintain list of RreqTable entry
139
 * \brief maintain list of RreqTable entry
 Lines 147-164   public: Link Here 
147
  void RemoveRreqEntry (Ipv4Address dst);
200
  void RemoveRreqEntry (Ipv4Address dst);
148
  // / Get the request count number for one destination address
201
  // / Get the request count number for one destination address
149
  uint32_t GetRreqCnt (Ipv4Address dst);
202
  uint32_t GetRreqCnt (Ipv4Address dst);
150
151
  //----------------------------------------------------------------------------------------------------------
203
  //----------------------------------------------------------------------------------------------------------
152
  /*
204
  /**
153
   * The following code generates new request id for each destination
205
   * The following code generates new request id for each destination
154
   */
206
   */
155
  // / Check for duplicate ids and save new entries if the id is not present in the table
207
  // / Check for duplicate ids and save new entries if the id is not present in the table
156
  uint32_t CheckUniqueRreqId (Ipv4Address dst);
208
  uint32_t CheckUniqueRreqId (Ipv4Address dst);
157
  // / Get the request id size
209
  // / Get the request id size
158
  uint32_t GetRreqSize ();
210
  uint32_t GetRreqSize ();
159
160
  // ---------------------------------------------------------------------------------------------------------
211
  // ---------------------------------------------------------------------------------------------------------
161
  /*
212
  /**
162
   * set the unidirectional entry as QUESTIONABLE state
213
   * set the unidirectional entry as QUESTIONABLE state
163
   */
214
   */
164
  void Invalidate ();
215
  void Invalidate ();
 Lines 175-184   public: Link Here 
175
  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
226
  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
176
  // / Remove all expired black list entries
227
  // / Remove all expired black list entries
177
  void PurgeNeighbor ();
228
  void PurgeNeighbor ();
229
  // ----------------------------------------------------------------------------------------------------------
230
  /**
231
   * Find the source request entry in the route request queue, return false if not found
232
   * \param src the source address we just received the source request
233
   * \param dst the destination address the request is targeted at
234
   * \param id the identification number for this request
235
   */
236
  bool FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t id);
178
237
179
private:
238
private:
180
  // / Timer for neighbor's list. Schedule Purge().
239
181
  Timer m_ntimer;
182
  // / The max # of requests to retransmit
240
  // / The max # of requests to retransmit
183
  uint32_t MaxRequestRexmt;
241
  uint32_t MaxRequestRexmt;
184
  // / The max request period among requests
242
  // / The max request period among requests
 Lines 200-212   private: Link Here 
200
  // / The state of the unidirectional link
258
  // / The state of the unidirectional link
201
  LinkStates m_linkStates;
259
  LinkStates m_linkStates;
202
  // / Map of entries
260
  // / Map of entries
203
  std::list<SourceRreqEntry> m_sourceRreq;
261
  std::list<ReceivedRreqEntry> m_sourceRequests;
204
  // / The id cache to ensure all the ids are unique
262
  // / The id cache to ensure all the ids are unique, it is used when sending out route request
205
  std::map<Ipv4Address, uint32_t> m_rreqIdCache;
263
  std::map<Ipv4Address, uint32_t> m_rreqIdCache;
206
  // / The cache to save route request table entries indexed with destination address
264
  // / The cache to save route request table entries indexed with destination address
207
  std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap;
265
  std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap;
208
  // / The cache to ensure all the route request from unique source
266
  // / The cache to ensure all the route request from unique source
209
  std::map<Ipv4Address, std::list<SourceRreqEntry> > m_rreqMap;
267
  std::map<Ipv4Address, std::list<ReceivedRreqEntry> > m_sourceRreqMap;
268
210
  // / The Black list
269
  // / The Black list
211
  std::vector<BlackList> m_blackList;
270
  std::vector<BlackList> m_blackList;
212
  // / Check if the entry is expired or not
271
  // / Check if the entry is expired or not
(-)ns3dev/src/dsr/wscript (-4 / +6 lines)
 Lines 9-20   def build(bld): Link Here 
9
        'model/dsr-fs-header.cc',
9
        'model/dsr-fs-header.cc',
10
        'model/dsr-option-header.cc',
10
        'model/dsr-option-header.cc',
11
        'model/dsr-maintain-buff.cc',
11
        'model/dsr-maintain-buff.cc',
12
        'model/dsr-passive-buff.cc',
12
        'model/dsr-rsendbuff.cc',
13
        'model/dsr-rsendbuff.cc',
13
        'model/dsr-rcache.cc',
14
        'model/dsr-rcache.cc',
14
        'model/dsr-rreq-table.cc',
15
        'model/dsr-rreq-table.cc',
15
        'model/dsr-gratuitous-reply-table.cc',
16
        'model/dsr-gratuitous-reply-table.cc',
16
	'model/dsr-errorbuff.cc',
17
        'model/dsr-errorbuff.cc',
17
	'model/dsr-network-queue.cc',
18
        'model/dsr-network-queue.cc',
18
        'helper/dsr-helper.cc',
19
        'helper/dsr-helper.cc',
19
        'helper/dsr-main-helper.cc',
20
        'helper/dsr-main-helper.cc',
20
        ]
21
        ]
 Lines 32-43   def build(bld): Link Here 
32
        'model/dsr-fs-header.h',
33
        'model/dsr-fs-header.h',
33
        'model/dsr-option-header.h',
34
        'model/dsr-option-header.h',
34
        'model/dsr-maintain-buff.h',
35
        'model/dsr-maintain-buff.h',
36
        'model/dsr-passive-buff.h',
35
        'model/dsr-rsendbuff.h',
37
        'model/dsr-rsendbuff.h',
36
        'model/dsr-rcache.h',
38
        'model/dsr-rcache.h',
37
        'model/dsr-rreq-table.h',
39
        'model/dsr-rreq-table.h',
38
        'model/dsr-gratuitous-reply-table.h',
40
        'model/dsr-gratuitous-reply-table.h',
39
	'model/dsr-errorbuff.h',
41
        'model/dsr-errorbuff.h',
40
	'model/dsr-network-queue.h',
42
        'model/dsr-network-queue.h',
41
        'helper/dsr-helper.h',
43
        'helper/dsr-helper.h',
42
        'helper/dsr-main-helper.h',
44
        'helper/dsr-main-helper.h',
43
        ]
45
        ]

Return to bug 1609