LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value a
bout whether to salvage a packet or not | 886 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value a
bout whether to salvage a packet or not |
887 | 887 |
888 DsrOptionSRHeader sourceRoute; | 888 DsrOptionSRHeader sourceRoute; |
889 std::vector<Ipv4Address> errorRoute = toDst.GetVector (); | 889 std::vector<Ipv4Address> errorRoute = toDst.GetVector (); |
890 sourceRoute.SetNodesAddress (errorRoute); | 890 sourceRoute.SetNodesAddress (errorRoute); |
891 /// When found a route and use it, UseExtends to the link cach
e | 891 /// When found a route and use it, UseExtends to the link cach
e |
892 if (m_routeCache->IsLinkCache ()) | 892 if (m_routeCache->IsLinkCache ()) |
893 { | 893 { |
894 m_routeCache->UseExtends (errorRoute); | 894 m_routeCache->UseExtends (errorRoute); |
895 } | 895 } |
896 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>((errorRoute.
size () - 2))); | 896 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> ((errorRoute
.size () - 2))); |
897 uint8_t salvage = 0; | 897 uint8_t salvage = 0; |
898 sourceRoute.SetSalvage (salvage); | 898 sourceRoute.SetSalvage (salvage); |
899 Ipv4Address nextHop = SearchNextHop (m_mainAddress, errorRoute
); // Get the next hop address | 899 Ipv4Address nextHop = SearchNextHop (m_mainAddress, errorRoute
); // Get the next hop address |
900 | 900 |
901 if (nextHop == "0.0.0.0") | 901 if (nextHop == "0.0.0.0") |
902 { | 902 { |
903 PacketNewRoute (dsrPacket, m_mainAddress, destination, pro
tocol); | 903 PacketNewRoute (dsrPacket, m_mainAddress, destination, pro
tocol); |
904 return; | 904 return; |
905 } | 905 } |
906 | 906 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 DsrOptionSRHeader sourceRoute; | 949 DsrOptionSRHeader sourceRoute; |
950 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the
route from the route entry we found | 950 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the
route from the route entry we found |
951 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); //
Get the next hop address for the route | 951 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); //
Get the next hop address for the route |
952 if (nextHop == "0.0.0.0") | 952 if (nextHop == "0.0.0.0") |
953 { | 953 { |
954 PacketNewRoute (dsrPacket, m_mainAddress, destination, protoco
l); | 954 PacketNewRoute (dsrPacket, m_mainAddress, destination, protoco
l); |
955 return; | 955 return; |
956 } | 956 } |
957 uint8_t salvage = 0; | 957 uint8_t salvage = 0; |
958 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in
the source route header of the packet | 958 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in
the source route header of the packet |
959 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>(nodeList.size ()
- 2)); // The segmentsLeft field will indicate the hops to go | 959 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> (nodeList.size (
) - 2)); // The segmentsLeft field will indicate the hops to go |
960 sourceRoute.SetSalvage (salvage); | 960 sourceRoute.SetSalvage (salvage); |
961 /// When found a route and use it, UseExtends to the link cache | 961 /// When found a route and use it, UseExtends to the link cache |
962 if (m_routeCache->IsLinkCache ()) | 962 if (m_routeCache->IsLinkCache ()) |
963 { | 963 { |
964 m_routeCache->UseExtends (nodeList); | 964 m_routeCache->UseExtends (nodeList); |
965 } | 965 } |
966 uint8_t length = sourceRoute.GetLength (); | 966 uint8_t length = sourceRoute.GetLength (); |
967 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 967 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
968 dsrRoutingHeader.AddDsrOption (sourceRoute); | 968 dsrRoutingHeader.AddDsrOption (sourceRoute); |
969 cleanP->AddHeader (dsrRoutingHeader); | 969 cleanP->AddHeader (dsrRoutingHeader); |
970 Ptr<const Packet> mtP = cleanP->Copy (); | 970 Ptr<const Packet> mtP = cleanP->Copy (); |
971 // Put the data packet in the maintenance queue for data packet re
transmission | 971 // Put the data packet in the maintenance queue for data packet re
transmission |
972 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m
_mainAddress, /*nextHop=*/ nextHop, | 972 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m
_mainAddress, /*nextHop=*/ nextHop, |
973 /*source=*/ m_mainAddress,
/*destination=*/ destination, /*ackId=*/ 0, | 973 /*source=*/ m_mainAddress,
/*destination=*/ destination, /*ackId=*/ 0, |
974 /*SegsLeft=*/ static_cast<
uint8_t>(nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); | 974 /*SegsLeft=*/ static_cast<
uint8_t> (nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); |
975 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the
packet the the maintenance buffer | 975 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the
packet the the maintenance buffer |
976 if (result) | 976 if (result) |
977 { | 977 { |
978 NetworkKey networkKey; | 978 NetworkKey networkKey; |
979 networkKey.m_ackId = newEntry.GetAckId (); | 979 networkKey.m_ackId = newEntry.GetAckId (); |
980 networkKey.m_ourAdd = newEntry.GetOurAdd (); | 980 networkKey.m_ourAdd = newEntry.GetOurAdd (); |
981 networkKey.m_nextHop = newEntry.GetNextHop (); | 981 networkKey.m_nextHop = newEntry.GetNextHop (); |
982 networkKey.m_source = newEntry.GetSrc (); | 982 networkKey.m_source = newEntry.GetSrc (); |
983 networkKey.m_destination = newEntry.GetDst (); | 983 networkKey.m_destination = newEntry.GetDst (); |
984 | 984 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); | 1094 Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
1095 dsr->CancelLinkPacketTimer (newEntry); | 1095 dsr->CancelLinkPacketTimer (newEntry); |
1096 } | 1096 } |
1097 | 1097 |
1098 // Receive only IP packets and packets destined for other hosts | 1098 // Receive only IP packets and packets destined for other hosts |
1099 if (packetType == NetDevice::PACKET_OTHERHOST) | 1099 if (packetType == NetDevice::PACKET_OTHERHOST) |
1100 { | 1100 { |
1101 //just to minimize debug output | 1101 //just to minimize debug output |
1102 NS_LOG_INFO (this << from << to << packetType << *pktMinusIpHdr); | 1102 NS_LOG_INFO (this << from << to << packetType << *pktMinusIpHdr); |
1103 | 1103 |
1104 uint8_t offset = static_cast<uint8_t>(dsrRouting.GetDsrOptionsOffset ());
// Get the offset for option header, 4 bytes in this case | 1104 uint8_t offset = static_cast<uint8_t> (dsrRouting.GetDsrOptionsOffset ());
// Get the offset for option header, 4 bytes in this case |
1105 uint8_t nextHeader = dsrRouting.GetNextHeader (); | 1105 uint8_t nextHeader = dsrRouting.GetNextHeader (); |
1106 uint32_t sourceId = dsrRouting.GetSourceId (); | 1106 uint32_t sourceId = dsrRouting.GetSourceId (); |
1107 Ipv4Address source = GetIPfromID (static_cast<uint16_t>(sourceId)); | 1107 Ipv4Address source = GetIPfromID (static_cast<uint16_t> (sourceId)); |
1108 | 1108 |
1109 // This packet is used to peek option type | 1109 // This packet is used to peek option type |
1110 pktMinusIpHdr->RemoveAtStart (offset); | 1110 pktMinusIpHdr->RemoveAtStart (offset); |
1111 /* | 1111 /* |
1112 * Peek data to get the option type as well as length and segmentsLeft fie
ld | 1112 * Peek data to get the option type as well as length and segmentsLeft fie
ld |
1113 */ | 1113 */ |
1114 uint32_t size = pktMinusIpHdr->GetSize (); | 1114 uint32_t size = pktMinusIpHdr->GetSize (); |
1115 uint8_t *data = new uint8_t[size]; | 1115 uint8_t *data = new uint8_t[size]; |
1116 pktMinusIpHdr->CopyData (data, size); | 1116 pktMinusIpHdr->CopyData (data, size); |
1117 uint8_t optionType = 0; | 1117 uint8_t optionType = 0; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 PacketNewRoute (cleanP, source, destination, protocol); | 1192 PacketNewRoute (cleanP, source, destination, protocol); |
1193 return; | 1193 return; |
1194 } | 1194 } |
1195 uint8_t salvage = 0; | 1195 uint8_t salvage = 0; |
1196 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet | 1196 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet |
1197 /// When found a route and use it, UseExtends to the link cache | 1197 /// When found a route and use it, UseExtends to the link cache |
1198 if (m_routeCache->IsLinkCache ()) | 1198 if (m_routeCache->IsLinkCache ()) |
1199 { | 1199 { |
1200 m_routeCache->UseExtends (nodeList); | 1200 m_routeCache->UseExtends (nodeList); |
1201 } | 1201 } |
1202 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>(nodeList.size () - 2));
// The segmentsLeft field will indicate the hops to go | 1202 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> (nodeList.size () - 2));
// The segmentsLeft field will indicate the hops to go |
1203 sourceRoute.SetSalvage (salvage); | 1203 sourceRoute.SetSalvage (salvage); |
1204 | 1204 |
1205 uint8_t length = sourceRoute.GetLength (); | 1205 uint8_t length = sourceRoute.GetLength (); |
1206 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 1206 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
1207 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1207 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1208 cleanP->AddHeader (dsrRoutingHeader); | 1208 cleanP->AddHeader (dsrRoutingHeader); |
1209 Ptr<const Packet> mtP = cleanP->Copy (); | 1209 Ptr<const Packet> mtP = cleanP->Copy (); |
1210 SetRoute (nextHop, m_mainAddress); | 1210 SetRoute (nextHop, m_mainAddress); |
1211 // Put the data packet in the maintenance queue for data packet retransmis
sion | 1211 // Put the data packet in the maintenance queue for data packet retransmis
sion |
1212 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_mainAdd
ress, /*nextHop=*/ nextHop, | 1212 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_mainAdd
ress, /*nextHop=*/ nextHop, |
1213 /*source=*/ source, /*destination=
*/ destination, /*ackId=*/ 0, | 1213 /*source=*/ source, /*destination=
*/ destination, /*ackId=*/ 0, |
1214 /*SegsLeft=*/ static_cast<uint8_t>
(nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); | 1214 /*SegsLeft=*/ static_cast<uint8_t>
(nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); |
1215 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the pack
et the the maintenance buffer | 1215 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the pack
et the the maintenance buffer |
1216 | 1216 |
1217 if (result) | 1217 if (result) |
1218 { | 1218 { |
1219 NetworkKey networkKey; | 1219 NetworkKey networkKey; |
1220 networkKey.m_ackId = newEntry.GetAckId (); | 1220 networkKey.m_ackId = newEntry.GetAckId (); |
1221 networkKey.m_ourAdd = newEntry.GetOurAdd (); | 1221 networkKey.m_ourAdd = newEntry.GetOurAdd (); |
1222 networkKey.m_nextHop = newEntry.GetNextHop (); | 1222 networkKey.m_nextHop = newEntry.GetNextHop (); |
1223 networkKey.m_source = newEntry.GetSrc (); | 1223 networkKey.m_source = newEntry.GetSrc (); |
1224 networkKey.m_destination = newEntry.GetDst (); | 1224 networkKey.m_destination = newEntry.GetDst (); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 PacketNewRoute (newPacket, m_mainAddress, destination, protocol); | 1330 PacketNewRoute (newPacket, m_mainAddress, destination, protocol); |
1331 return; | 1331 return; |
1332 } | 1332 } |
1333 DsrOptionSRHeader sourceRoute; | 1333 DsrOptionSRHeader sourceRoute; |
1334 sourceRoute.SetNodesAddress (nodeList); | 1334 sourceRoute.SetNodesAddress (nodeList); |
1335 /// When found a route and use it, UseExtends to the link cache | 1335 /// When found a route and use it, UseExtends to the link cache |
1336 if (m_routeCache->IsLinkCache ()) | 1336 if (m_routeCache->IsLinkCache ()) |
1337 { | 1337 { |
1338 m_routeCache->UseExtends (nodeList); | 1338 m_routeCache->UseExtends (nodeList); |
1339 } | 1339 } |
1340 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>(nodeList.size () - 2)); | 1340 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> (nodeList.size () - 2)); |
1341 uint8_t srLength = sourceRoute.GetLength (); | 1341 uint8_t srLength = sourceRoute.GetLength (); |
1342 uint8_t length = (srLength + rerrLength); | 1342 uint8_t length = (srLength + rerrLength); |
1343 | 1343 |
1344 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4); | 1344 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4); |
1345 dsrRoutingHeader.AddDsrOption (rerrUnreachHeader); | 1345 dsrRoutingHeader.AddDsrOption (rerrUnreachHeader); |
1346 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1346 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1347 newPacket->AddHeader (dsrRoutingHeader); | 1347 newPacket->AddHeader (dsrRoutingHeader); |
1348 | 1348 |
1349 SetRoute (nextHop, m_mainAddress); | 1349 SetRoute (nextHop, m_mainAddress); |
1350 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | 1350 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 PacketNewRoute (cleanP, source, destination, protocol); | 1480 PacketNewRoute (cleanP, source, destination, protocol); |
1481 return; | 1481 return; |
1482 } | 1482 } |
1483 uint8_t salvage = 0; | 1483 uint8_t salvage = 0; |
1484 sourceRoute.SetNodesAddress (nodeList); // Save the whole route
in the source route header of the packet | 1484 sourceRoute.SetNodesAddress (nodeList); // Save the whole route
in the source route header of the packet |
1485 /// When found a route and use it, UseExtends to the link cache | 1485 /// When found a route and use it, UseExtends to the link cache |
1486 if (m_routeCache->IsLinkCache ()) | 1486 if (m_routeCache->IsLinkCache ()) |
1487 { | 1487 { |
1488 m_routeCache->UseExtends (nodeList); | 1488 m_routeCache->UseExtends (nodeList); |
1489 } | 1489 } |
1490 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>((nodeList.size () -
2))); // The segmentsLeft field will indicate the hops to go | 1490 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> ((nodeList.size () -
2))); // The segmentsLeft field will indicate the hops to go |
1491 sourceRoute.SetSalvage (salvage); | 1491 sourceRoute.SetSalvage (salvage); |
1492 | 1492 |
1493 uint8_t length = sourceRoute.GetLength (); | 1493 uint8_t length = sourceRoute.GetLength (); |
1494 | 1494 |
1495 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 1495 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
1496 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1496 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1497 cleanP->AddHeader (dsrRoutingHeader); | 1497 cleanP->AddHeader (dsrRoutingHeader); |
1498 | 1498 |
1499 Ptr<const Packet> mtP = cleanP->Copy (); | 1499 Ptr<const Packet> mtP = cleanP->Copy (); |
1500 NS_LOG_DEBUG ("maintain packet size " << cleanP->GetSize ()); | 1500 NS_LOG_DEBUG ("maintain packet size " << cleanP->GetSize ()); |
1501 // Put the data packet in the maintenance queue for data packet retran
smission | 1501 // Put the data packet in the maintenance queue for data packet retran
smission |
1502 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_main
Address, /*nextHop=*/ nextHop, | 1502 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_main
Address, /*nextHop=*/ nextHop, |
1503 /*source=*/ source, /*destinat
ion=*/ destination, /*ackId=*/ 0, | 1503 /*source=*/ source, /*destinat
ion=*/ destination, /*ackId=*/ 0, |
1504 /*SegsLeft=*/ static_cast<uint
8_t>(nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); | 1504 /*SegsLeft=*/ static_cast<uint
8_t> (nodeList.size () - 2), /*expire time=*/ m_maxMaintainTime); |
1505 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer | 1505 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer |
1506 if (result) | 1506 if (result) |
1507 { | 1507 { |
1508 NetworkKey networkKey; | 1508 NetworkKey networkKey; |
1509 networkKey.m_ackId = newEntry.GetAckId (); | 1509 networkKey.m_ackId = newEntry.GetAckId (); |
1510 networkKey.m_ourAdd = newEntry.GetOurAdd (); | 1510 networkKey.m_ourAdd = newEntry.GetOurAdd (); |
1511 networkKey.m_nextHop = newEntry.GetNextHop (); | 1511 networkKey.m_nextHop = newEntry.GetNextHop (); |
1512 networkKey.m_source = newEntry.GetSrc (); | 1512 networkKey.m_source = newEntry.GetSrc (); |
1513 networkKey.m_destination = newEntry.GetDst (); | 1513 networkKey.m_destination = newEntry.GetDst (); |
1514 | 1514 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 sourceRoute.SetNumberAddress (numberAddress); | 1581 sourceRoute.SetNumberAddress (numberAddress); |
1582 tmpP->RemoveHeader (sourceRoute); // this is a clean packet with
out any dsr involved headers | 1582 tmpP->RemoveHeader (sourceRoute); // this is a clean packet with
out any dsr involved headers |
1583 | 1583 |
1584 DsrOptionAckReqHeader ackReq; | 1584 DsrOptionAckReqHeader ackReq; |
1585 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1585 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1586 ackReq.SetAckId (m_ackId); | 1586 ackReq.SetAckId (m_ackId); |
1587 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1587 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1588 DsrRoutingHeader newDsrRoutingHeader; | 1588 DsrRoutingHeader newDsrRoutingHeader; |
1589 newDsrRoutingHeader.SetNextHeader (protocol); | 1589 newDsrRoutingHeader.SetNextHeader (protocol); |
1590 newDsrRoutingHeader.SetMessageType (2); | 1590 newDsrRoutingHeader.SetMessageType (2); |
1591 newDsrRoutingHeader.SetSourceId (static_cast<uint16_t>(sourceId)); | 1591 newDsrRoutingHeader.SetSourceId (static_cast<uint16_t> (sourceId)); |
1592 newDsrRoutingHeader.SetDestId (static_cast<uint16_t>(destinationId)); | 1592 newDsrRoutingHeader.SetDestId (static_cast<uint16_t> (destinationId)); |
1593 newDsrRoutingHeader.SetPayloadLength (length + 4); | 1593 newDsrRoutingHeader.SetPayloadLength (length + 4); |
1594 newDsrRoutingHeader.AddDsrOption (sourceRoute); | 1594 newDsrRoutingHeader.AddDsrOption (sourceRoute); |
1595 newDsrRoutingHeader.AddDsrOption (ackReq); | 1595 newDsrRoutingHeader.AddDsrOption (ackReq); |
1596 dsrP->AddHeader (newDsrRoutingHeader); | 1596 dsrP->AddHeader (newDsrRoutingHeader); |
1597 // give the dsrP value to packet and then return | 1597 // give the dsrP value to packet and then return |
1598 packet = dsrP; | 1598 packet = dsrP; |
1599 return m_ackId; | 1599 return m_ackId; |
1600 } | 1600 } |
1601 | 1601 |
1602 void | 1602 void |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 } | 1733 } |
1734 | 1734 |
1735 bool | 1735 bool |
1736 DsrRouting::SendRealDown (DsrNetworkQueueEntry & newEntry) | 1736 DsrRouting::SendRealDown (DsrNetworkQueueEntry & newEntry) |
1737 { | 1737 { |
1738 NS_LOG_FUNCTION (this); | 1738 NS_LOG_FUNCTION (this); |
1739 Ipv4Address source = newEntry.GetSourceAddress (); | 1739 Ipv4Address source = newEntry.GetSourceAddress (); |
1740 Ipv4Address nextHop = newEntry.GetNextHopAddress (); | 1740 Ipv4Address nextHop = newEntry.GetNextHopAddress (); |
1741 Ptr<Packet> packet = newEntry.GetPacket ()->Copy (); | 1741 Ptr<Packet> packet = newEntry.GetPacket ()->Copy (); |
1742 Ptr<Ipv4Route> route = newEntry.GetIpv4Route (); | 1742 Ptr<Ipv4Route> route = newEntry.GetIpv4Route (); |
1743 m_downTarget (packet, source, nextHop, static_cast<uint8_t>(GetProtocolNumber
()), route); | 1743 m_downTarget (packet, source, nextHop, static_cast<uint8_t> (GetProtocolNumber
()), route); |
1744 return true; | 1744 return true; |
1745 } | 1745 } |
1746 | 1746 |
1747 void | 1747 void |
1748 DsrRouting::SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute, Ipv4Addr
ess nextHop, uint8_t protocol) | 1748 DsrRouting::SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute, Ipv4Addr
ess nextHop, uint8_t protocol) |
1749 { | 1749 { |
1750 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); | 1750 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); |
1751 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1751 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1752 | 1752 |
1753 // Reconstruct the route and Retransmit the data packet | 1753 // Reconstruct the route and Retransmit the data packet |
(...skipping 28 matching lines...) Expand all Loading... |
1782 uint8_t length = sourceRoute.GetLength (); | 1782 uint8_t length = sourceRoute.GetLength (); |
1783 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 1783 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
1784 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1784 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1785 | 1785 |
1786 p->AddHeader (dsrRoutingHeader); | 1786 p->AddHeader (dsrRoutingHeader); |
1787 | 1787 |
1788 Ptr<const Packet> mtP = p->Copy (); | 1788 Ptr<const Packet> mtP = p->Copy (); |
1789 // Put the data packet in the maintenance queue for data packet retran
smission | 1789 // Put the data packet in the maintenance queue for data packet retran
smission |
1790 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_main
Address, /*nextHop=*/ nextHop, | 1790 DsrMaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_main
Address, /*nextHop=*/ nextHop, |
1791 /*source=*/ source, /*destination=*/ desti
nation, /*ackId=*/ 0, | 1791 /*source=*/ source, /*destination=*/ desti
nation, /*ackId=*/ 0, |
1792 /*SegsLeft=*/ static_cast<uint8_t>(nodeLis
t.size () - 2), /*expire time=*/ m_maxMaintainTime); | 1792 /*SegsLeft=*/ static_cast<uint8_t> (nodeLi
st.size () - 2), /*expire time=*/ m_maxMaintainTime); |
1793 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer | 1793 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer |
1794 | 1794 |
1795 if (result) | 1795 if (result) |
1796 { | 1796 { |
1797 NetworkKey networkKey; | 1797 NetworkKey networkKey; |
1798 networkKey.m_ackId = newEntry.GetAckId (); | 1798 networkKey.m_ackId = newEntry.GetAckId (); |
1799 networkKey.m_ourAdd = newEntry.GetOurAdd (); | 1799 networkKey.m_ourAdd = newEntry.GetOurAdd (); |
1800 networkKey.m_nextHop = newEntry.GetNextHop (); | 1800 networkKey.m_nextHop = newEntry.GetNextHop (); |
1801 networkKey.m_source = newEntry.GetSrc (); | 1801 networkKey.m_source = newEntry.GetSrc (); |
1802 networkKey.m_destination = newEntry.GetDst (); | 1802 networkKey.m_destination = newEntry.GetDst (); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2266 DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Add
ress dst, uint8_t protocol) | 2266 DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Add
ress dst, uint8_t protocol) |
2267 { | 2267 { |
2268 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol); | 2268 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol); |
2269 // Create two copies of packet | 2269 // Create two copies of packet |
2270 Ptr<Packet> p = packet->Copy (); | 2270 Ptr<Packet> p = packet->Copy (); |
2271 Ptr<Packet> newPacket = packet->Copy (); | 2271 Ptr<Packet> newPacket = packet->Copy (); |
2272 // Remove the routing header in a whole to get a clean packet | 2272 // Remove the routing header in a whole to get a clean packet |
2273 DsrRoutingHeader dsrRoutingHeader; | 2273 DsrRoutingHeader dsrRoutingHeader; |
2274 p->RemoveHeader (dsrRoutingHeader); | 2274 p->RemoveHeader (dsrRoutingHeader); |
2275 // Remove offset of dsr routing header | 2275 // Remove offset of dsr routing header |
2276 uint8_t offset = static_cast<uint8_t>(dsrRoutingHeader.GetDsrOptionsOffset ())
; | 2276 uint8_t offset = static_cast<uint8_t> (dsrRoutingHeader.GetDsrOptionsOffset ()
); |
2277 newPacket->RemoveAtStart (offset); | 2277 newPacket->RemoveAtStart (offset); |
2278 | 2278 |
2279 // Get the number of routers' address field | 2279 // Get the number of routers' address field |
2280 uint8_t buf[2]; | 2280 uint8_t buf[2]; |
2281 newPacket->CopyData (buf, sizeof(buf)); | 2281 newPacket->CopyData (buf, sizeof(buf)); |
2282 uint8_t numberAddress = (buf[1] - 2) / 4; | 2282 uint8_t numberAddress = (buf[1] - 2) / 4; |
2283 | 2283 |
2284 DsrOptionSRHeader sourceRoute; | 2284 DsrOptionSRHeader sourceRoute; |
2285 sourceRoute.SetNumberAddress (numberAddress); | 2285 sourceRoute.SetNumberAddress (numberAddress); |
2286 newPacket->RemoveHeader (sourceRoute); | 2286 newPacket->RemoveHeader (sourceRoute); |
(...skipping 17 matching lines...) Expand all Loading... |
2304 if (nextHop == "0.0.0.0") | 2304 if (nextHop == "0.0.0.0") |
2305 { | 2305 { |
2306 PacketNewRoute (p, source, dst, protocol); | 2306 PacketNewRoute (p, source, dst, protocol); |
2307 return; | 2307 return; |
2308 } | 2308 } |
2309 // Increase the salvage count by 1 | 2309 // Increase the salvage count by 1 |
2310 salvage++; | 2310 salvage++; |
2311 DsrOptionSRHeader sourceRoute1; | 2311 DsrOptionSRHeader sourceRoute1; |
2312 sourceRoute1.SetSalvage (salvage); | 2312 sourceRoute1.SetSalvage (salvage); |
2313 sourceRoute1.SetNodesAddress (nodeList); // Save the whole route in th
e source route header of the packet | 2313 sourceRoute1.SetNodesAddress (nodeList); // Save the whole route in th
e source route header of the packet |
2314 sourceRoute1.SetSegmentsLeft (static_cast<uint8_t>(nodeList.size () - 2));
// The segmentsLeft field will indicate the hops to go | 2314 sourceRoute1.SetSegmentsLeft (static_cast<uint8_t> (nodeList.size () - 2))
; // The segmentsLeft field will indicate the hops to go |
2315 /// When found a route and use it, UseExtends to the link cache | 2315 /// When found a route and use it, UseExtends to the link cache |
2316 if (m_routeCache->IsLinkCache ()) | 2316 if (m_routeCache->IsLinkCache ()) |
2317 { | 2317 { |
2318 m_routeCache->UseExtends (nodeList); | 2318 m_routeCache->UseExtends (nodeList); |
2319 } | 2319 } |
2320 uint8_t length = sourceRoute1.GetLength (); | 2320 uint8_t length = sourceRoute1.GetLength (); |
2321 NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute1.G
etLength ())); | 2321 NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute1.G
etLength ())); |
2322 newDsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 2322 newDsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
2323 newDsrRoutingHeader.AddDsrOption (sourceRoute1); | 2323 newDsrRoutingHeader.AddDsrOption (sourceRoute1); |
2324 p->AddHeader (newDsrRoutingHeader); | 2324 p->AddHeader (newDsrRoutingHeader); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 void | 2663 void |
2664 DsrRouting::ForwardPacket (Ptr<const Packet> packet, | 2664 DsrRouting::ForwardPacket (Ptr<const Packet> packet, |
2665 DsrOptionSRHeader &sourceRoute, | 2665 DsrOptionSRHeader &sourceRoute, |
2666 Ipv4Header const& ipv4Header, | 2666 Ipv4Header const& ipv4Header, |
2667 Ipv4Address source, | 2667 Ipv4Address source, |
2668 Ipv4Address nextHop, | 2668 Ipv4Address nextHop, |
2669 Ipv4Address targetAddress, | 2669 Ipv4Address targetAddress, |
2670 uint8_t protocol, | 2670 uint8_t protocol, |
2671 Ptr<Ipv4Route> route) | 2671 Ptr<Ipv4Route> route) |
2672 { | 2672 { |
2673 NS_UNUSED(ipv4Header); | 2673 NS_UNUSED (ipv4Header); |
2674 NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << targetA
ddress << (uint32_t)protocol << route); | 2674 NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << targetA
ddress << (uint32_t)protocol << route); |
2675 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 2675 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
2676 | 2676 |
2677 DsrRoutingHeader dsrRoutingHeader; | 2677 DsrRoutingHeader dsrRoutingHeader; |
2678 dsrRoutingHeader.SetNextHeader (protocol); | 2678 dsrRoutingHeader.SetNextHeader (protocol); |
2679 dsrRoutingHeader.SetMessageType (2); | 2679 dsrRoutingHeader.SetMessageType (2); |
2680 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 2680 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
2681 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress)); | 2681 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress)); |
2682 | 2682 |
2683 // We get the salvage value in sourceRoute header and set it to route error he
ader if triggered error | 2683 // We get the salvage value in sourceRoute header and set it to route error he
ader if triggered error |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2755 DsrRoutingHeader dsrRoutingHeader; | 2755 DsrRoutingHeader dsrRoutingHeader; |
2756 dsrRoutingHeader.SetNextHeader (protocol); | 2756 dsrRoutingHeader.SetNextHeader (protocol); |
2757 dsrRoutingHeader.SetMessageType (1); | 2757 dsrRoutingHeader.SetMessageType (1); |
2758 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 2758 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
2759 dsrRoutingHeader.SetDestId (255); | 2759 dsrRoutingHeader.SetDestId (255); |
2760 | 2760 |
2761 DsrOptionRreqHeader rreqHeader; // has an ali
gnment of 4n+0 | 2761 DsrOptionRreqHeader rreqHeader; // has an ali
gnment of 4n+0 |
2762 rreqHeader.AddNodeAddress (m_mainAddress); // Add our ow
n address in the header | 2762 rreqHeader.AddNodeAddress (m_mainAddress); // Add our ow
n address in the header |
2763 rreqHeader.SetTarget (destination); | 2763 rreqHeader.SetTarget (destination); |
2764 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the
Id cache for duplicate ones | 2764 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the
Id cache for duplicate ones |
2765 rreqHeader.SetId (static_cast<uint16_t>(m_requestId)); | 2765 rreqHeader.SetId (static_cast<uint16_t> (m_requestId)); |
2766 | 2766 |
2767 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rr
eqHeader to the dsr extension header | 2767 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rr
eqHeader to the dsr extension header |
2768 uint8_t length = rreqHeader.GetLength (); | 2768 uint8_t length = rreqHeader.GetLength (); |
2769 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); | 2769 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2); |
2770 packet->AddHeader (dsrRoutingHeader); | 2770 packet->AddHeader (dsrRoutingHeader); |
2771 | 2771 |
2772 // Schedule the route requests retry with non-propagation set true | 2772 // Schedule the route requests retry with non-propagation set true |
2773 bool nonProp = true; | 2773 bool nonProp = true; |
2774 std::vector<Ipv4Address> address; | 2774 std::vector<Ipv4Address> address; |
2775 address.push_back (source); | 2775 address.push_back (source); |
(...skipping 29 matching lines...) Expand all Loading... |
2805 * Found a route the dst, construct the source route option header | 2805 * Found a route the dst, construct the source route option header |
2806 */ | 2806 */ |
2807 DsrOptionSRHeader sourceRoute; | 2807 DsrOptionSRHeader sourceRoute; |
2808 std::vector<Ipv4Address> ip = toDst.GetVector (); | 2808 std::vector<Ipv4Address> ip = toDst.GetVector (); |
2809 sourceRoute.SetNodesAddress (ip); | 2809 sourceRoute.SetNodesAddress (ip); |
2810 /// When found a route and use it, UseExtends to the link cache | 2810 /// When found a route and use it, UseExtends to the link cache |
2811 if (m_routeCache->IsLinkCache ()) | 2811 if (m_routeCache->IsLinkCache ()) |
2812 { | 2812 { |
2813 m_routeCache->UseExtends (ip); | 2813 m_routeCache->UseExtends (ip); |
2814 } | 2814 } |
2815 sourceRoute.SetSegmentsLeft (static_cast<uint8_t>(ip.size () - 2)); | 2815 sourceRoute.SetSegmentsLeft (static_cast<uint8_t> (ip.size () - 2)); |
2816 sourceRoute.SetSalvage (salvage); | 2816 sourceRoute.SetSalvage (salvage); |
2817 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the
next hop address | 2817 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the
next hop address |
2818 NS_LOG_DEBUG ("The nextHop address " << nextHop); | 2818 NS_LOG_DEBUG ("The nextHop address " << nextHop); |
2819 Ptr<Packet> packet = Create<Packet> (); | 2819 Ptr<Packet> packet = Create<Packet> (); |
2820 if (nextHop == "0.0.0.0") | 2820 if (nextHop == "0.0.0.0") |
2821 { | 2821 { |
2822 NS_LOG_DEBUG ("Error next hop address"); | 2822 NS_LOG_DEBUG ("Error next hop address"); |
2823 PacketNewRoute (packet, m_mainAddress, dst, protocol); | 2823 PacketNewRoute (packet, m_mainAddress, dst, protocol); |
2824 return; | 2824 return; |
2825 } | 2825 } |
(...skipping 21 matching lines...) Expand all Loading... |
2847 dsrRoutingHeader.SetNextHeader (protocol); | 2847 dsrRoutingHeader.SetNextHeader (protocol); |
2848 dsrRoutingHeader.SetMessageType (1); | 2848 dsrRoutingHeader.SetMessageType (1); |
2849 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); | 2849 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); |
2850 dsrRoutingHeader.SetDestId (255); | 2850 dsrRoutingHeader.SetDestId (255); |
2851 | 2851 |
2852 Ptr<Packet> dstP = Create<Packet> (); | 2852 Ptr<Packet> dstP = Create<Packet> (); |
2853 DsrOptionRreqHeader rreqHeader; // has an a
lignment of 4n+0 | 2853 DsrOptionRreqHeader rreqHeader; // has an a
lignment of 4n+0 |
2854 rreqHeader.AddNodeAddress (m_mainAddress); // Add our
own address in the header | 2854 rreqHeader.AddNodeAddress (m_mainAddress); // Add our
own address in the header |
2855 rreqHeader.SetTarget (originalDst); | 2855 rreqHeader.SetTarget (originalDst); |
2856 m_requestId = m_rreqTable->CheckUniqueRreqId (originalDst); // Check
the Id cache for duplicate ones | 2856 m_requestId = m_rreqTable->CheckUniqueRreqId (originalDst); // Check
the Id cache for duplicate ones |
2857 rreqHeader.SetId (static_cast<uint16_t>(m_requestId)); | 2857 rreqHeader.SetId (static_cast<uint16_t> (m_requestId)); |
2858 | 2858 |
2859 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader
to the dsr extension header | 2859 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader
to the dsr extension header |
2860 dsrRoutingHeader.AddDsrOption (rerr); | 2860 dsrRoutingHeader.AddDsrOption (rerr); |
2861 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); | 2861 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); |
2862 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4); | 2862 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4); |
2863 dstP->AddHeader (dsrRoutingHeader); | 2863 dstP->AddHeader (dsrRoutingHeader); |
2864 // Schedule the route requests retry, propagate the route request message
as it contains error | 2864 // Schedule the route requests retry, propagate the route request message
as it contains error |
2865 bool nonProp = false; | 2865 bool nonProp = false; |
2866 std::vector<Ipv4Address> address; | 2866 std::vector<Ipv4Address> address; |
2867 address.push_back (m_mainAddress); | 2867 address.push_back (m_mainAddress); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3312 Ptr<Packet> packet = p->Copy (); // Save a copy of the received pac
ket | 3312 Ptr<Packet> packet = p->Copy (); // Save a copy of the received pac
ket |
3313 /* | 3313 /* |
3314 * When forwarding or local deliver packets, this one should be used always!! | 3314 * When forwarding or local deliver packets, this one should be used always!! |
3315 */ | 3315 */ |
3316 DsrRoutingHeader dsrRoutingHeader; | 3316 DsrRoutingHeader dsrRoutingHeader; |
3317 packet->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in
whole | 3317 packet->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in
whole |
3318 Ptr<Packet> copy = packet->Copy (); | 3318 Ptr<Packet> copy = packet->Copy (); |
3319 | 3319 |
3320 uint8_t protocol = dsrRoutingHeader.GetNextHeader (); | 3320 uint8_t protocol = dsrRoutingHeader.GetNextHeader (); |
3321 uint32_t sourceId = dsrRoutingHeader.GetSourceId (); | 3321 uint32_t sourceId = dsrRoutingHeader.GetSourceId (); |
3322 Ipv4Address source = GetIPfromID (static_cast<uint16_t>(sourceId)); | 3322 Ipv4Address source = GetIPfromID (static_cast<uint16_t> (sourceId)); |
3323 NS_LOG_INFO ("The source address " << source << " with source id " << sourceId
); | 3323 NS_LOG_INFO ("The source address " << source << " with source id " << sourceId
); |
3324 /* | 3324 /* |
3325 * Get the IP source and destination address | 3325 * Get the IP source and destination address |
3326 */ | 3326 */ |
3327 Ipv4Address src = ip.GetSource (); | 3327 Ipv4Address src = ip.GetSource (); |
3328 | 3328 |
3329 bool isPromisc = false; | 3329 bool isPromisc = false; |
3330 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the o
ffset for option header, 8 bytes in this case | 3330 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the o
ffset for option header, 8 bytes in this case |
3331 | 3331 |
3332 // This packet is used to peek option type | 3332 // This packet is used to peek option type |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3533 { | 3533 { |
3534 if ((*i)->GetOptionNumber () == optionNumber) | 3534 if ((*i)->GetOptionNumber () == optionNumber) |
3535 { | 3535 { |
3536 return *i; | 3536 return *i; |
3537 } | 3537 } |
3538 } | 3538 } |
3539 return 0; | 3539 return 0; |
3540 } | 3540 } |
3541 } /* namespace dsr */ | 3541 } /* namespace dsr */ |
3542 } /* namespace ns3 */ | 3542 } /* namespace ns3 */ |
LEFT | RIGHT |