# HG changeset patch # User Tom Henderson # Date 1226069661 28800 # Node ID 448c5176bf8a44f16e928578d547aeec43ecaebe # Parent cc6a7f93dc3f66e31f2f4a024f7faed5477678f3 Add an InternetStackHelper method to do ascii tracing on drop events diff -r cc6a7f93dc3f -r 448c5176bf8a src/helper/internet-stack-helper.cc --- a/src/helper/internet-stack-helper.cc Thu Nov 06 15:04:25 2008 -0800 +++ b/src/helper/internet-stack-helper.cc Fri Nov 07 06:54:21 2008 -0800 @@ -92,6 +92,29 @@ InternetStackHelper::Install (Ptr } void +InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n) +{ + Packet::EnablePrinting (); + std::ostringstream oss; + for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) + { + Ptr node = *i; + oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop"; + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + oss.str (""); + oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop"; + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + oss.str (""); + } +} + +void +InternetStackHelper::EnableAsciiAll (std::ostream &os) +{ + EnableAscii (os, NodeContainer::GetGlobal ()); +} + +void InternetStackHelper::EnablePcapAll (std::string filename) { Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup); @@ -157,4 +180,11 @@ InternetStackHelper::GetStream (uint32_t return trace.writer; } +void +InternetStackHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +{ + *os << "d " << Simulator::Now ().GetSeconds () << " "; + *os << path << " " << *packet << std::endl; +} + } // namespace ns3 diff -r cc6a7f93dc3f -r 448c5176bf8a src/helper/internet-stack-helper.h --- a/src/helper/internet-stack-helper.h Thu Nov 06 15:04:25 2008 -0800 +++ b/src/helper/internet-stack-helper.h Fri Nov 07 06:54:21 2008 -0800 @@ -70,6 +70,25 @@ public: void SetNscStack(std::string soname); /** + * \param os output stream + * \param n node container + * + * Enable ascii output on these drop traces, for each node in the NodeContainer.. + * /NodeList/[i]/$ns3ArpL3Protocol/Drop + * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop + */ + static void EnableAscii (std::ostream &os, NodeContainer n); + + /** + * \param os output stream + * + * Enable ascii output on these drop traces, for all nodes. + * /NodeList/[i]/$ns3ArpL3Protocol/Drop + * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop + */ + static void EnableAsciiAll (std::ostream &os); + + /** * Enable pcap output on each protocol instance which is of the * ns3::Ipv4L3Protocol type. Both Tx and Rx events will be logged. * @@ -95,6 +114,7 @@ private: uint32_t interfaceId; Ptr writer; }; + static void AsciiDropEvent (std::ostream *os, std::string path, Ptr packet); static std::string m_pcapBaseFilename; static uint32_t GetNodeIndex (std::string context); static std::vector m_traces; # HG changeset patch # User Tom Henderson # Date 1226072135 28800 # Node ID cc52dff4f7df36354e4d79d400df7dd47a3a85aa # Parent 448c5176bf8a44f16e928578d547aeec43ecaebe Allow /32 addresses to be configured via Ipv4AddressHelper diff -r 448c5176bf8a -r cc52dff4f7df src/helper/ipv4-address-helper.cc --- a/src/helper/ipv4-address-helper.cc Fri Nov 07 06:54:21 2008 -0800 +++ b/src/helper/ipv4-address-helper.cc Fri Nov 07 07:35:35 2008 -0800 @@ -63,9 +63,6 @@ Ipv4AddressHelper::SetBase ( // NS_ASSERT_MSG((m_network & ~m_mask) == 0, "Ipv4AddressHelper::SetBase(): Inconsistent network and mask"); - - NS_ASSERT_MSG((m_address & m_mask) == 0, - "Ipv4AddressHelper::SetBase(): Inconsistent address and mask"); // // Figure out how much to shift network numbers to get them aligned, and what # HG changeset patch # User Tom Henderson # Date 1226102986 28800 # Node ID 7c0168cd98bb86e908bd1f54c61d7efc7e326ebd # Parent cc52dff4f7df36354e4d79d400df7dd47a3a85aa Add utility function to fetch an all-ones netmask, for comparison operators diff -r cc52dff4f7df -r 7c0168cd98bb src/node/ipv4-address.cc --- a/src/node/ipv4-address.cc Fri Nov 07 07:35:35 2008 -0800 +++ b/src/node/ipv4-address.cc Fri Nov 07 16:09:46 2008 -0800 @@ -125,6 +125,12 @@ Ipv4Mask::GetZero (void) { static Ipv4Mask zero = Ipv4Mask ("0.0.0.0"); return zero; +} +Ipv4Mask +Ipv4Mask::GetOnes (void) +{ + static Ipv4Mask ones = Ipv4Mask ("255.255.255.255"); + return ones; } Ipv4Address::Ipv4Address () diff -r cc52dff4f7df -r 7c0168cd98bb src/node/ipv4-address.h --- a/src/node/ipv4-address.h Fri Nov 07 07:35:35 2008 -0800 +++ b/src/node/ipv4-address.h Fri Nov 07 16:09:46 2008 -0800 @@ -179,6 +179,7 @@ public: static Ipv4Mask GetLoopback (void); static Ipv4Mask GetZero (void); + static Ipv4Mask GetOnes (void); private: uint32_t m_mask; # HG changeset patch # User Tom Henderson # Date 1226103818 28800 # Node ID b42dcf8c81286a684e5d2e2363cdd3eec1fc41f2 # Parent 7c0168cd98bb86e908bd1f54c61d7efc7e326ebd Do not try to convert limited broadcast address to subnet-directed, when interface has a /32 address diff -r 7c0168cd98bb -r b42dcf8c8128 src/internet-stack/udp-socket-impl.cc --- a/src/internet-stack/udp-socket-impl.cc Fri Nov 07 16:09:46 2008 -0800 +++ b/src/internet-stack/udp-socket-impl.cc Fri Nov 07 16:23:38 2008 -0800 @@ -349,8 +349,13 @@ UdpSocketImpl::DoSendTo (Ptr p, } } // - // If dest is sent to the limited broadcast address (all ones), - // convert it to send a copy of the packet out of every interface + // If dest is set to the limited broadcast address (all ones), + // convert it to send a copy of the packet out of every + // interface as a subnet-directed broadcast. + // Exception: if the interface has a /32 address, there is no + // valid subnet-directed broadcast, so send it as limited broadcast + // Note also that some systems will only send limited broadcast packets + // out of the "default" interface; here we send it out all interfaces // if (dest.IsBroadcast ()) { @@ -359,13 +364,27 @@ UdpSocketImpl::DoSendTo (Ptr p, { Ipv4Address addri = ipv4->GetAddress (i); Ipv4Mask maski = ipv4->GetNetworkMask (i); - Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski); - NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast - << " (mask is " << maski << ")"); - m_udp->Send (p->Copy (), addri, bcast, - m_endPoint->GetLocalPort (), port); - NotifyDataSent (p->GetSize ()); - NotifySend (GetTxAvailable ()); + if (maski == Ipv4Mask::GetOnes ()) + { + // if the network mask is 255.255.255.255, do not convert dest + NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << dest + << " (mask is " << maski << ")"); + m_udp->Send (p->Copy (), addri, dest, + m_endPoint->GetLocalPort (), port); + NotifyDataSent (p->GetSize ()); + NotifySend (GetTxAvailable ()); + } + else + { + // Convert to subnet-directed broadcast + Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski); + NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast + << " (mask is " << maski << ")"); + m_udp->Send (p->Copy (), addri, bcast, + m_endPoint->GetLocalPort (), port); + NotifyDataSent (p->GetSize ()); + NotifySend (GetTxAvailable ()); + } } NS_LOG_LOGIC ("Limited broadcast end."); return p->GetSize(); # HG changeset patch # User Tom Henderson # Date 1226172519 28800 # Node ID 0f57a4ca876f918d40c5bc7c7a08c647e7b062d4 # Parent b42dcf8c81286a684e5d2e2363cdd3eec1fc41f2 Extend SubnetDirectedBroadcast-related methods to cover /32 interface case diff -r b42dcf8c8128 -r 0f57a4ca876f src/node/ipv4-address.cc --- a/src/node/ipv4-address.cc Fri Nov 07 16:23:38 2008 -0800 +++ b/src/node/ipv4-address.cc Sat Nov 08 11:28:39 2008 -0800 @@ -170,12 +170,22 @@ Ipv4Address Ipv4Address Ipv4Address::GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const { + if (mask == Ipv4Mask::GetOnes ()) + { + NS_ASSERT_MSG (false, "Trying to get subnet-directed broadcast address with an all-ones netmask"); + } return Ipv4Address (Get () | mask.GetInverse ()); } bool Ipv4Address::IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const { + if (mask == Ipv4Mask::GetOnes ()) + { + // If the mask is 255.255.255.255, there is no subnet directed + // broadcast for this address. + return false; + } return ( (Get () | mask.GetInverse ()) == Get () ); } diff -r b42dcf8c8128 -r 0f57a4ca876f src/node/ipv4-address.h --- a/src/node/ipv4-address.h Fri Nov 07 16:23:38 2008 -0800 +++ b/src/node/ipv4-address.h Sat Nov 08 11:28:39 2008 -0800 @@ -120,7 +120,9 @@ public: * \brief Generate subnet-directed broadcast address corresponding to mask * * The subnet-directed broadcast address has the host bits set to all - * ones. + * ones. If this method is called with a mask of 255.255.255.255, + * (i.e., the address is a /32 address), the program will assert, since + * there is no subnet associated with a /32 address. * * \param mask a network mask */ # HG changeset patch # User Tom Henderson # Date 1226172584 28800 # Node ID 6f7be404d3ba7f778a6cdfe5498845999dc0ac4a # Parent 0f57a4ca876f918d40c5bc7c7a08c647e7b062d4 Log warning for TTL exceeded diff -r 0f57a4ca876f -r 6f7be404d3ba src/internet-stack/ipv4-l3-protocol.cc --- a/src/internet-stack/ipv4-l3-protocol.cc Sat Nov 08 11:28:39 2008 -0800 +++ b/src/internet-stack/ipv4-l3-protocol.cc Sat Nov 08 11:29:44 2008 -0800 @@ -827,6 +827,7 @@ Ipv4L3Protocol::DoForward (uint32_t ifIn Ptr icmp = GetIcmp (); icmp->SendTimeExceededTtl (ipHeader, packet); } + NS_LOG_WARN ("TTL exceeded. Drop."); m_dropTrace (packet); return; }