diff -r c009d3d36e85 examples/simple-p2p.cc --- a/examples/simple-p2p.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/examples/simple-p2p.cc Wed Jun 13 19:20:00 2007 +0100 @@ -164,6 +164,18 @@ int main (int argc, char *argv[]) ooff->Start(Seconds(1.1)); ooff->Stop (Seconds(10.0)); + // Create a 3rd flow from n3 to , starting at time 1.1 seconds + ooff = Create ( + n3, + Ipv4Address("255.255.255.255"), + 80, + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); + // Here, finish off packet routing configuration // This will likely set by some global StaticRouting object in the future Ptr ipv4; diff -r c009d3d36e85 src/internet-node/arp-cache.cc --- a/src/internet-node/arp-cache.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/src/internet-node/arp-cache.cc Wed Jun 13 18:52:06 2007 +0100 @@ -109,6 +109,8 @@ ArpCache::Entry * ArpCache::Entry * ArpCache::Add (Ipv4Address to) { + NS_ASSERT (m_arpCache.find (to) == m_arpCache.end ()); + ArpCache::Entry *entry = new ArpCache::Entry (this); m_arpCache[to] = entry; return entry; diff -r c009d3d36e85 src/internet-node/arp-ipv4-interface.cc --- a/src/internet-node/arp-ipv4-interface.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/src/internet-node/arp-ipv4-interface.cc Wed Jun 13 18:52:06 2007 +0100 @@ -21,6 +21,7 @@ */ #include "ns3/packet.h" +#include "ns3/debug.h" #include "ns3/composite-trace-resolver.h" #include "ns3/node.h" #include "ns3/net-device.h" @@ -60,7 +61,19 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4 { Ptr arp = m_node->QueryInterface (ArpPrivate::iid); MacAddress hardwareDestination; - bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); + bool found; + + if (dest.IsBroadcast ()) + { + hardwareDestination = GetDevice ()->GetBroadcast (); + found = true; + } + else + { + Ptr arp = m_node->QueryInterface (ArpPrivate::iid); + found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); + } + if (found) { GetDevice ()->Send (p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER); diff -r c009d3d36e85 src/internet-node/arp-l3-protocol.cc --- a/src/internet-node/arp-l3-protocol.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/src/internet-node/arp-l3-protocol.cc Wed Jun 13 18:52:06 2007 +0100 @@ -87,6 +87,13 @@ ArpL3Protocol::Receive(Packet& packet, P ArpCache *cache = FindCache (device); ArpHeader arp; packet.RemoveHeader (arp); + + NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") << + " node="<GetId ()<<", got request from " << + arp.GetSourceIpv4Address () << " for address " << + arp.GetDestinationIpv4Address () << "; we have address " << + cache->GetInterface ()->GetAddress ()); + if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { @@ -128,6 +135,12 @@ ArpL3Protocol::Receive(Packet& packet, P // XXX report packet as dropped. } } + else + { + NS_DEBUG ("node="<GetId ()<<", got request from " << + arp.GetSourceIpv4Address () << " for unknown address " << + arp.GetDestinationIpv4Address () << " -- drop"); + } } bool ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, @@ -203,6 +216,11 @@ ArpL3Protocol::SendArpRequest (ArpCache ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) { ArpHeader arp; + NS_DEBUG ("ARP: sending request from node "<GetId ()<< + " || src: " << cache->GetDevice ()->GetAddress () << + " / " << cache->GetInterface ()->GetAddress () << + " || dst: " << cache->GetDevice ()->GetBroadcast () << + " / " << to); arp.SetRequest (cache->GetDevice ()->GetAddress (), cache->GetInterface ()->GetAddress (), cache->GetDevice ()->GetBroadcast (), @@ -216,6 +234,10 @@ ArpL3Protocol::SendArpReply (ArpCache co ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac) { ArpHeader arp; + NS_DEBUG ("ARP: sending reply from node "<GetId ()<< + "|| src: " << cache->GetDevice ()->GetAddress () << + " / " << cache->GetInterface ()->GetAddress () << + " || dst: " << toMac << " / " << toIp); arp.SetReply (cache->GetDevice ()->GetAddress (), cache->GetInterface ()->GetAddress (), toMac, toIp); diff -r c009d3d36e85 src/internet-node/ipv4-l3-protocol.cc --- a/src/internet-node/ipv4-l3-protocol.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/src/internet-node/ipv4-l3-protocol.cc Wed Jun 13 18:52:06 2007 +0100 @@ -404,23 +404,39 @@ Ipv4L3Protocol::Send (Packet const &pack m_identification ++; - // XXX Note here that in most ipv4 stacks in the world, - // the route calculation for an outgoing packet is not - // done in the ip layer. It is done within the application - // socket when the first packet is sent to avoid this - // costly lookup on a per-packet basis. - // That would require us to get the route from the packet, - // most likely with a packet tag. The higher layers do not - // do this yet for us. - Ipv4Route *route = Lookup (ipHeader.GetDestination ()); - if (route == 0) - { - NS_DEBUG ("not for me -- forwarding but no route to host. drop."); - m_dropTrace (packet); - return; - } - - SendRealOut (packet, ipHeader, *route); + if (destination.IsBroadcast ()) + { + Packet packet1 = packet; + packet1.AddHeader (ipHeader); + + for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin (); + ifaceIter != m_interfaces.end (); ifaceIter++) + { + Ipv4Interface *outInterface = *ifaceIter; + // XXX log trace here. + NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); + outInterface->Send (packet1, destination); + } + } + else + { + // XXX Note here that in most ipv4 stacks in the world, + // the route calculation for an outgoing packet is not + // done in the ip layer. It is done within the application + // socket when the first packet is sent to avoid this + // costly lookup on a per-packet basis. + // That would require us to get the route from the packet, + // most likely with a packet tag. The higher layers do not + // do this yet for us. + Ipv4Route *route = Lookup (ipHeader.GetDestination ()); + if (route == 0) + { + NS_DEBUG ("not for me -- forwarding but no route to host. drop."); + m_dropTrace (packet); + return; + } + SendRealOut (packet, ipHeader, *route); + } } void @@ -470,7 +486,7 @@ Ipv4L3Protocol::Forwarding (Packet const } } - if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) + if (ipHeader.GetDestination ().IsBroadcast ()) { NS_DEBUG ("for me 3"); return false; diff -r c009d3d36e85 src/node/ipv4-address.cc --- a/src/node/ipv4-address.cc Wed Jun 13 18:40:38 2007 +0100 +++ b/src/node/ipv4-address.cc Wed Jun 13 19:02:38 2007 +0100 @@ -145,6 +145,18 @@ Ipv4Address::IsEqual (Ipv4Address other) } } +bool +Ipv4Address::IsBroadcast (void) const +{ + return (m_address == 0xffffffffU); +} + +Ipv4Address +Ipv4Address::CombineMask (Ipv4Mask const &mask) const +{ + return Ipv4Address (GetHostOrder () & mask.GetHostOrder ()); +} + bool Ipv4Address::IsMulticast (void) { diff -r c009d3d36e85 src/node/ipv4-address.h --- a/src/node/ipv4-address.h Wed Jun 13 18:40:38 2007 +0100 +++ b/src/node/ipv4-address.h Wed Jun 13 19:05:51 2007 +0100 @@ -26,6 +26,8 @@ #include namespace ns3 { + +class Ipv4Mask; /** Ipv4 addresses are stored in host order in * this class. @@ -80,8 +82,19 @@ public: */ void Print (std::ostream &os) const; - bool IsBroadcast (void); + bool IsBroadcast (void) const; bool IsMulticast (void); + + /** + * \brief Combine this address with a network mask + * + * This method returns an IPv4 address that is this address combined + * (bitwise and) with a network mask, yielding an IPv4 network + * address. + * + * \param a network mask + */ + Ipv4Address CombineMask (Ipv4Mask const &mask) const; static Ipv4Address GetZero (void); static Ipv4Address GetAny (void);