src/internet/model/ipv4-l3-protocol.cc
changeset 9145 5752b425cdf5
parent 9110 9ae62bcda73e
child 9710 df21b904fce3
--- a/src/internet/model/ipv4-l3-protocol.cc	Fri Nov 16 22:27:18 2012 +0100
+++ b/src/internet/model/ipv4-l3-protocol.cc	Tue Nov 20 17:52:39 2012 -0500
@@ -54,6 +54,10 @@
   static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
     .SetParent<Ipv4> ()
     .AddConstructor<Ipv4L3Protocol> ()
+    .AddAttribute ("DefaultTos", "The TOS value set by default on all outgoing packets generated on this node.",
+                   UintegerValue (0),
+                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTos),
+                   MakeUintegerChecker<uint8_t> ())
     .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
                    UintegerValue (64),
                    MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
@@ -87,6 +91,7 @@
 
 Ipv4L3Protocol::Ipv4L3Protocol()
   : m_identification (0)
+
 {
   NS_LOG_FUNCTION (this);
 }
@@ -558,6 +563,14 @@
       ttl = tag.GetTtl ();
     }
 
+  uint8_t tos = m_defaultTos;
+  SocketIpTosTag ipTosTag;
+  found = packet->RemovePacketTag (ipTosTag);
+  if (found)
+    {
+      tos = ipTosTag.GetTos ();
+    }
+
   // Handle a few cases:
   // 1) packet is destined to limited broadcast address
   // 2) packet is destined to a subnet-directed broadcast address
@@ -569,7 +582,7 @@
   if (destination.IsBroadcast () || destination.IsLocalMulticast ())
     {
       NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 1:  limited broadcast");
-      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment);
+      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
       uint32_t ifaceIndex = 0;
       for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
            ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
@@ -601,7 +614,7 @@
               destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ())   )
             {
               NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 2:  subnet directed bcast to " << ifAddr.GetLocal ());
-              ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment);
+              ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
               Ptr<Packet> packetCopy = packet->Copy ();
               m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
               packetCopy->AddHeader (ipHeader);
@@ -617,7 +630,7 @@
   if (route && route->GetGateway () != Ipv4Address ())
     {
       NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 3:  passed in with route");
-      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment);
+      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
       int32_t interface = GetInterfaceForDevice (route->GetOutputDevice ());
       m_sendOutgoingTrace (ipHeader, packet, interface);
       SendRealOut (route, packet->Copy (), ipHeader);
@@ -636,7 +649,7 @@
   NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 5:  passed in with no route " << destination);
   Socket::SocketErrno errno_; 
   Ptr<NetDevice> oif (0); // unused for now
-  ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment);
+  ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
   Ptr<Ipv4Route> newRoute;
   if (m_routingProtocol != 0)
     {
@@ -669,6 +682,7 @@
   uint8_t protocol,
   uint16_t payloadSize,
   uint8_t ttl,
+  uint8_t tos,
   bool mayFragment)
 {
   NS_LOG_FUNCTION (this << source << destination << (uint16_t)protocol << payloadSize << (uint16_t)ttl << mayFragment);
@@ -678,6 +692,7 @@
   ipHeader.SetProtocol (protocol);
   ipHeader.SetPayloadSize (payloadSize);
   ipHeader.SetTtl (ttl);
+  ipHeader.SetTos (tos);
   if (mayFragment == true)
     {
       ipHeader.SetMayFragment ();
@@ -704,7 +719,6 @@
                              Ipv4Header const &ipHeader)
 {
   NS_LOG_FUNCTION (this << packet << &ipHeader);
-
   if (route == 0)
     {
       NS_LOG_WARN ("No route to host.  Drop.");