real multicast enet addr, more source routes, default multicast route

This commit is contained in:
Craig Dowell committed 2007-08-27 23:46:14 -07:00
1 parent c566eebcd0
commit e3bb600840
12 files changed
+275 -37

No files matched your search

+70 -9
View File
@@ -61,6 +61,74 @@ ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
return resolver;
}
//
// RFC 1112 says that an IP host group address is mapped to an Ethernet
// multicast address by placing the low-order 23-bits of the IP address into
// the low-order 23 bits of the Ethernet multicast address 01-00-5E-00-00-00
// (hex). These are completely different animals and they're encapsulated
// very nicely. Translation: This isn't going to be very pretty.
//
Address
ArpIpv4Interface::MakeMulticastAddress(Ipv4Address multicastGroup)
{
NS_DEBUG ("ArpIpv4Interface::MakeMulticastAddress (" << multicastGroup <<
")");
//
// First, get the generic multicast address from the device. Since it is
// connected to this object, and this object is an IPV4 stack, we hope that
// it is really an Eui48Address. If it's not, then we don't know what to do.
//
Address hardwareDestination = GetDevice ()->GetMulticast ();
NS_DEBUG ("ArpIpv4Interface::MakeMulticastAddress (): "
"Device multicast address: " << hardwareDestination);
Eui48Address etherAddr = Eui48Address::ConvertFrom (hardwareDestination);
//
// We now have the multicast address in an abstract 48-bit container. We
// need to pull it out so we can play with it. When we're done, we have the
// high order bits in etherBuffer[0], etc.
//
uint8_t etherBuffer[6];
etherAddr.CopyTo (etherBuffer);
//
// If the device is playing the game correctly, the low order 23 bits of the
// multicast base address will be zero.
//
NS_ASSERT_MSG((etherBuffer[4] & 0x7f) == 0,
"ArpIpv4Interface::SendTo (): Expected low order bits zeroed");
NS_ASSERT_MSG(etherBuffer[5] == 0,
"ArpIpv4Interface::SendTo (): Expected low order bits zeroed");
NS_ASSERT_MSG(etherBuffer[6] == 0,
"ArpIpv4Interface::SendTo (): Expected low order bits zeroed");
//
// Now we need to pull the raw bits out of the Ipv4 destination address.
//
uint8_t ipBuffer[4];
multicastGroup.Serialize (ipBuffer);
//
// We need to place the low order 23 bits of the IP address into the low order
// 23 bits of the ethernet address.
//
etherBuffer[3] |= ipBuffer[1] & 0x7f;
etherBuffer[4] = ipBuffer[2];
etherBuffer[5] = ipBuffer[3];
//
// Now, etherBuffer has the desired ethernet multicast address. We have to
// suck these bits back into the Eui48Address; and then suck those bits back
// into the abstract hardwareAddress.
//
etherAddr.CopyFrom (etherBuffer);
//
// Implicit conversion (operator Address ()) is defined for Eui48Address, so
// use it.
//
NS_DEBUG ("ArpIpv4Interface::MakeMulticastAddress (): "
"multicast address is " << etherAddr);
return etherAddr;
}
void
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
{
@@ -87,15 +155,8 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
NS_ASSERT_MSG(GetDevice ()->IsMulticast (),
"ArpIpv4Interface::SendTo (): Sending multicast packet over "
"non-multicast device");
// XXX
//
// An IP host group address is mapped to an Ethernet multicast address
// by placing the low-order 23-bits of the IP address into the low-order
// 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex).
//
// Currently no easy way to or bit from Ipv4Address into Address
//
hardwareDestination = GetDevice ()->GetMulticast ();
hardwareDestination = MakeMulticastAddress(dest);
found = true;
}
else
+2
View File
@@ -24,6 +24,7 @@
#include "ipv4-interface.h"
#include "ns3/ptr.h"
#include "ns3/eui48-address.h"
namespace ns3 {
@@ -46,6 +47,7 @@ class ArpIpv4Interface : public Ipv4Interface
virtual void SendTo (Packet p, Ipv4Address dest);
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
Ptr<Node> m_node;
Address MakeMulticastAddress (Ipv4Address multicastGroup);
};
}//namespace ns3
+13
View File
@@ -105,6 +105,16 @@ Ipv4Impl::AddMulticastRoute (Ipv4Address origin,
m_ipv4->AddMulticastRoute (origin, group, inputInterface, outputInterfaces);
}
void
Ipv4Impl::SetDefaultMulticastRoute (Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces)
{
m_ipv4->SetDefaultMulticastRoute (origin, group, inputInterface,
outputInterfaces);
}
uint32_t
Ipv4Impl::GetNMulticastRoutes (void) const
{
@@ -208,6 +218,9 @@ Ipv4Impl::GetSourceAddress (Ipv4Address destination) const
}
else
{
//
// If we can't find any address, just leave it 0.0.0.0
//
return Ipv4Address::GetAny ();
}
}
+4
View File
@@ -62,6 +62,10 @@ public:
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
virtual void SetDefaultMulticastRoute (Ipv4Address origin,
Ipv4Address group, uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
virtual uint32_t GetNMulticastRoutes (void) const;
virtual Ipv4MulticastRoute GetMulticastRoute (uint32_t i) const;
+36 -8
View File
@@ -355,6 +355,20 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin,
outputInterfaces);
}
void
Ipv4L3Protocol::SetDefaultMulticastRoute (
Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces)
{
NS_DEBUG("Ipv4L3Protocol::SetDefaultMulticastRoute (" << origin << ", " <<
group << ", " << inputInterface << ", " << &outputInterfaces << ")");
m_staticRouting->SetDefaultMulticastRoute (origin, group, inputInterface,
outputInterfaces);
}
uint32_t
Ipv4L3Protocol::GetNMulticastRoutes (void) const
{
@@ -768,7 +782,11 @@ Ipv4L3Protocol::GetIfIndexForDestination (
{
NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (" << destination <<
", " << &ifIndex << ")");
//
// The first thing we do in trying to determine a source address is to
// consult the routing protocols. These will also check for a default route
// if one has been set.
//
for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
i != m_routingProtocols.end ();
i++)
@@ -785,13 +803,13 @@ Ipv4L3Protocol::GetIfIndexForDestination (
}
}
//
// If there's no routing table entry telling us what single interface will be
// used to send a packet to this destination, we'll have to just pick one.
// If there's no routing table entry telling us what *single* interface will
// be used to send a packet to this destination, we'll have to just pick one.
// If there's only one interface on this node, a good answer isn't very hard
// to come up with. Before jumping to any conclusions, remember that the
// zeroth interface is the loopback interface, so what we actually want is
// a situation where there are exactly two interfaces on the node, in which
// case interface one is the "single" interface.
// case interface one is the "single" interface connected to the outside world.
//
if (GetNInterfaces () == 2)
{
@@ -802,11 +820,21 @@ Ipv4L3Protocol::GetIfIndexForDestination (
}
//
// If we fall through to here, we have a node with multiple interfaces and
// no routes to guide us in determining what interface to choose. The last
// choice is to use the one set in the default route.
//
// no routes to guide us in determining what interface to choose. Either
// no default route was found (for unicast or multicast), or in the case of a
// multicast, the default route contained multiple outbound interfaces.
//
// The fallback position is to just get the unicast default route and use
// the outgoing interface specified there. We don't want to leave the source
// address unset, so we just assert here.
//
// N.B. that in the case of a multicast with a route containing multiple
// outgoing interfaces, the source address of packets from that node will be
// set to the IP address of the interface set in the default unicast route.
// Also, in the case of a broadcast, the same will be true.
//
NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
"Using default route");
"Using default unicast route");
Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
NS_ASSERT_MSG(route,
+5
View File
@@ -163,6 +163,11 @@ public:
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
void SetDefaultMulticastRoute (Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
uint32_t GetNMulticastRoutes (void) const;
Ipv4MulticastRoute *GetMulticastRoute (uint32_t i) const;
+105 -9
View File
@@ -27,6 +27,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Ipv4StaticRouting");
namespace ns3 {
Ipv4StaticRouting::Ipv4StaticRouting ()
: m_defaultRoute (0), m_defaultMulticastRoute (0)
{
}
void
Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest,
Ipv4Address nextHop,
@@ -95,10 +100,24 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin,
m_multicastRoutes.push_back (route);
}
void
Ipv4StaticRouting::SetDefaultMulticastRoute(
Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces)
{
Ipv4MulticastRoute *route = new Ipv4MulticastRoute ();
*route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group,
inputInterface, outputInterfaces);
delete m_defaultMulticastRoute;
m_defaultMulticastRoute = route;
}
uint32_t
Ipv4StaticRouting::GetNMulticastRoutes (void) const
{
return m_multicastRoutes.size ();
return m_multicastRoutes.size () + m_defaultMulticastRoute ? 1 : 0;
}
Ipv4MulticastRoute *
@@ -106,17 +125,54 @@ Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const
{
NS_ASSERT_MSG(index < m_multicastRoutes.size (),
"Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
uint32_t tmp = 0;
for (MulticastRoutesCI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
i++)
//
// From an external point of view the default route appears to be in slot 0
// of the routing table. The implementation, however, puts it in a separate
// place. So, if a client asks for index 0 and we have a default multicast
// route, we have to return it from that different place
// (m_defaultMulticastRoute).
//
if (index == 0 && m_defaultMulticastRoute != 0)
{
if (tmp == index)
return m_defaultMulticastRoute;
}
//
// If there is a default multicast route present, a client will just assume
// that it is in slot zero and there is one "extra" zeroth route in the table.
// To return the correct indexed entry in our list, we have to decrement the
// index to take into account the default route not being in the actual list.
// Since we fell through to here, we've taken care of the case where the
// index was zero.
//
if (m_defaultMulticastRoute != 0)
{
NS_ASSERT(index > 0);
index--;
}
if (index < m_multicastRoutes.size ())
{
uint32_t tmp = 0;
for (MulticastRoutesCI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
i++)
{
return *i;
if (tmp == index)
{
return *i;
}
tmp++;
}
tmp++;
}
return 0;
}
Ipv4MulticastRoute *
Ipv4StaticRouting::GetDefaultMulticastRoute () const
{
if (m_defaultMulticastRoute != 0)
{
return m_defaultMulticastRoute;
}
return 0;
}
@@ -126,6 +182,9 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface)
{
//
// This method does not attempt to delete the multicast route.
//
for (MulticastRoutesI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
i++)
@@ -145,6 +204,32 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin,
void
Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index)
{
//
// From an external point of view the default route appears to be in slot 0
// of the routing table. The implementation, however, puts it in a separate
// place. So, if a client asks to delete index 0 and we have a default
// multicast route set, we have to delete it from that different place
// (m_defaultMulticastRoute).
//
if (index == 0 && m_defaultMulticastRoute != 0)
{
delete m_defaultMulticastRoute;
m_defaultMulticastRoute = 0;
}
//
// If there is a default multicast route present, a client will just assume
// that it is in slot zero and there is one "extra" zeroth route in the table.
// To return the correct indexed entry in our list, we have to decrement the
// index to take into account the default route not being in the actual list.
// Since we fell through to here, we've taken care of the case where the
// index was zero.
//
if (m_defaultMulticastRoute != 0)
{
NS_ASSERT(index > 0);
index--;
}
uint32_t tmp = 0;
for (MulticastRoutesI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
@@ -215,6 +300,12 @@ Ipv4StaticRouting::LookupStatic (
}
}
}
if (m_defaultMulticastRoute != 0)
{
return m_defaultMulticastRoute;
}
return 0;
}
@@ -492,6 +583,11 @@ Ipv4StaticRouting::DoDispose (void)
{
delete (*i);
}
if (m_defaultMulticastRoute != 0)
{
delete m_defaultMulticastRoute;
m_defaultMulticastRoute = 0;
}
Ipv4RoutingProtocol::DoDispose ();
}
+8 -1
View File
@@ -49,7 +49,7 @@ class Ipv4StaticRouting : public Ipv4RoutingProtocol
{
public:
Ipv4StaticRouting () : m_defaultRoute (0) {}
Ipv4StaticRouting ();
virtual bool RequestRoute (uint32_t ifIndex,
Ipv4Header const &ipHeader,
@@ -83,8 +83,14 @@ public:
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
void SetDefaultMulticastRoute (Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces);
uint32_t GetNMulticastRoutes (void) const;
Ipv4MulticastRoute *GetMulticastRoute (uint32_t i) const;
Ipv4MulticastRoute *GetDefaultMulticastRoute (void) const;
void RemoveMulticastRoute (Ipv4Address origin,
Ipv4Address group,
@@ -114,6 +120,7 @@ private:
HostRoutes m_hostRoutes;
NetworkRoutes m_networkRoutes;
Ipv4Route *m_defaultRoute;
Ipv4MulticastRoute *m_defaultMulticastRoute;
MulticastRoutes m_multicastRoutes;
};