Implementation cut over to use Ipv4InterfaceAddress
This commit is contained in:
@@ -87,13 +87,13 @@ main (int argc, char *argv[])
|
||||
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
|
||||
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
|
||||
|
||||
ipv4A->SetAddress (ifIndexA, Ipv4Address ("172.16.1.1"));
|
||||
ipv4A->SetNetworkMask (ifIndexA, Ipv4Mask ("255.255.255.255"));
|
||||
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4A->AddAddress (ifIndexA, ifInAddrA);
|
||||
ipv4A->SetMetric (ifIndexA, 1);
|
||||
ipv4A->SetUp (ifIndexA);
|
||||
|
||||
ipv4C->SetAddress (ifIndexC, Ipv4Address ("192.168.1.1"));
|
||||
ipv4C->SetNetworkMask (ifIndexC, Ipv4Mask ("255.255.255.255"));
|
||||
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4C->AddAddress (ifIndexC, ifInAddrC);
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
@@ -105,7 +105,7 @@ main (int argc, char *argv[])
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (Ipv4Address("192.168.1.1"), port)));
|
||||
Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
|
||||
|
||||
@@ -353,7 +353,7 @@ main (int argc, char *argv[])
|
||||
uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
|
||||
Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
|
||||
// Let's fetch the IP address of the last node, which is on Ipv4Interface 1
|
||||
Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1);
|
||||
Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1, 0).GetLocal ();
|
||||
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (remoteAddr, port)));
|
||||
|
||||
@@ -87,13 +87,13 @@ main (int argc, char *argv[])
|
||||
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
|
||||
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
|
||||
|
||||
ipv4A->SetAddress (ifIndexA, Ipv4Address ("172.16.1.1"));
|
||||
ipv4A->SetNetworkMask (ifIndexA, Ipv4Mask ("255.255.255.255"));
|
||||
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4A->AddAddress (ifIndexA, ifInAddrA);
|
||||
ipv4A->SetMetric (ifIndexA, 1);
|
||||
ipv4A->SetUp (ifIndexA);
|
||||
|
||||
ipv4C->SetAddress (ifIndexC, Ipv4Address ("192.168.1.1"));
|
||||
ipv4C->SetNetworkMask (ifIndexC, Ipv4Mask ("255.255.255.255"));
|
||||
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4C->AddAddress (ifIndexC, ifInAddrC);
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
@@ -107,7 +107,7 @@ main (int argc, char *argv[])
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (Ipv4Address("192.168.1.1"), port)));
|
||||
Address (InetSocketAddress (ifInAddrC.GetLocal (), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
|
||||
|
||||
@@ -343,12 +343,16 @@ TapBridge::CreateTap (void)
|
||||
Ptr<Node> n = nd->GetNode ();
|
||||
Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
|
||||
uint32_t index = ipv4->FindInterfaceForDevice (nd);
|
||||
Ipv4Address ipv4Address = ipv4->GetAddress (index);
|
||||
if (ipv4->GetNAddresses (index) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Underlying bridged NetDevice has multiple IP addresses; using first one.");
|
||||
}
|
||||
Ipv4Address ipv4Address = ipv4->GetAddress (index, 0).GetLocal ();
|
||||
|
||||
//
|
||||
// The net mask is sitting right there next to the ipv4 address.
|
||||
//
|
||||
Ipv4Mask ipv4Mask = ipv4->GetNetworkMask (index);
|
||||
Ipv4Mask ipv4Mask = ipv4->GetAddress (index, 0).GetMask ();
|
||||
|
||||
//
|
||||
// The MAC address should also already be assigned and waiting for us in
|
||||
|
||||
@@ -139,8 +139,8 @@ Ipv4AddressHelper::Assign (const NetDeviceContainer &c)
|
||||
NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Allocate(): "
|
||||
"Interface index not found");
|
||||
|
||||
ipv4->SetAddress (interface, NewAddress ());
|
||||
ipv4->SetNetworkMask (interface, m_mask);
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mask);
|
||||
ipv4->AddAddress (interface, ipv4Addr);
|
||||
ipv4->SetMetric (interface, 1);
|
||||
ipv4->SetUp (interface);
|
||||
retval.Add (ipv4, interface);
|
||||
|
||||
@@ -23,12 +23,13 @@ Ipv4InterfaceContainer::GetN (void) const
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4InterfaceContainer::GetAddress (uint32_t i) const
|
||||
Ipv4InterfaceContainer::GetAddress (uint32_t i, uint32_t j) const
|
||||
{
|
||||
Ptr<Ipv4> ipv4 = m_interfaces[i].first;
|
||||
uint32_t interface = m_interfaces[i].second;
|
||||
return ipv4->GetAddress (interface);
|
||||
return ipv4->GetAddress (interface, j).GetLocal ();
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4InterfaceContainer::SetMetric (uint32_t i, uint16_t metric)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,16 @@ public:
|
||||
*/
|
||||
uint32_t GetN (void) const;
|
||||
|
||||
Ipv4Address GetAddress (uint32_t i) const;
|
||||
/**
|
||||
* \returns the IPv4 address of the j'th address of the interface
|
||||
* corresponding to index i.
|
||||
*
|
||||
* If the second parameter is omitted, the zeroth indexed address of
|
||||
* the interface is returned. Unless IP aliaising is being used on
|
||||
* the interface, the second parameter may typically be omitted.
|
||||
*/
|
||||
Ipv4Address GetAddress (uint32_t i, uint32_t j = 0) const;
|
||||
|
||||
void SetMetric (uint32_t i, uint16_t metric);
|
||||
|
||||
void Add (Ptr<Ipv4> ipv4, uint32_t interface);
|
||||
|
||||
@@ -106,7 +106,8 @@ ArpIpv4Interface::SendTo (Ptr<Packet> p, Ipv4Address dest)
|
||||
NS_LOG_FUNCTION (this << p << dest);
|
||||
|
||||
NS_ASSERT (GetDevice () != 0);
|
||||
if (dest == GetAddress ())
|
||||
// XXX multi-address case
|
||||
if (dest == GetAddress (0).GetLocal ())
|
||||
{
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
|
||||
@@ -124,9 +125,9 @@ ArpIpv4Interface::SendTo (Ptr<Packet> p, Ipv4Address dest)
|
||||
m_node->GetObject<ArpL3Protocol> ();
|
||||
Address hardwareDestination;
|
||||
bool found;
|
||||
|
||||
// XXX multi-address case
|
||||
if (dest.IsBroadcast () ||
|
||||
dest.IsSubnetDirectedBroadcast (GetNetworkMask ()) )
|
||||
dest.IsSubnetDirectedBroadcast (GetAddress (0).GetMask ()) )
|
||||
{
|
||||
NS_LOG_LOGIC ("IsBroadcast");
|
||||
hardwareDestination = GetDevice ()->GetBroadcast ();
|
||||
|
||||
@@ -142,28 +142,29 @@ ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t prot
|
||||
NS_LOG_LOGIC ("ARP: Cannot remove ARP header");
|
||||
return;
|
||||
}
|
||||
|
||||
// XXX multi-address case
|
||||
NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
|
||||
" node="<<m_node->GetId ()<<", got request from " <<
|
||||
arp.GetSourceIpv4Address () << " for address " <<
|
||||
arp.GetDestinationIpv4Address () << "; we have address " <<
|
||||
cache->GetInterface ()->GetAddress ());
|
||||
cache->GetInterface ()->GetAddress (0).GetLocal ());
|
||||
|
||||
/**
|
||||
* Note: we do not update the ARP cache when we receive an ARP request
|
||||
* from an unknown node. See bug #107
|
||||
*/
|
||||
|
||||
// XXX multi-address case
|
||||
if (arp.IsRequest () &&
|
||||
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ())
|
||||
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress (0).GetLocal ())
|
||||
{
|
||||
NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " <<
|
||||
arp.GetSourceIpv4Address () << " -- send reply");
|
||||
SendArpReply (cache, arp.GetSourceIpv4Address (),
|
||||
arp.GetSourceHardwareAddress ());
|
||||
}
|
||||
// XXX multi-address case
|
||||
else if (arp.IsReply () &&
|
||||
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
|
||||
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (0).GetLocal ()) &&
|
||||
arp.GetDestinationHardwareAddress () == device->GetAddress ())
|
||||
{
|
||||
Ipv4Address from = arp.GetSourceIpv4Address ();
|
||||
@@ -284,11 +285,12 @@ ArpL3Protocol::SendArpRequest (Ptr<const ArpCache> cache, Ipv4Address to)
|
||||
ArpHeader arp;
|
||||
NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<<
|
||||
" || src: " << cache->GetDevice ()->GetAddress () <<
|
||||
" / " << cache->GetInterface ()->GetAddress () <<
|
||||
" / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
|
||||
" || dst: " << cache->GetDevice ()->GetBroadcast () <<
|
||||
" / " << to);
|
||||
// XXX multi-address case
|
||||
arp.SetRequest (cache->GetDevice ()->GetAddress (),
|
||||
cache->GetInterface ()->GetAddress (),
|
||||
cache->GetInterface ()->GetAddress (0).GetLocal (),
|
||||
cache->GetDevice ()->GetBroadcast (),
|
||||
to);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
@@ -303,10 +305,11 @@ ArpL3Protocol::SendArpReply (Ptr<const ArpCache> cache, Ipv4Address toIp, Addres
|
||||
ArpHeader arp;
|
||||
NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<<
|
||||
"|| src: " << cache->GetDevice ()->GetAddress () <<
|
||||
" / " << cache->GetInterface ()->GetAddress () <<
|
||||
" / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
|
||||
" || dst: " << toMac << " / " << toIp);
|
||||
// XXX multi-address case
|
||||
arp.SetReply (cache->GetDevice ()->GetAddress (),
|
||||
cache->GetInterface ()->GetAddress (),
|
||||
cache->GetInterface ()->GetAddress (0).GetLocal (),
|
||||
toMac, toIp);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (arp);
|
||||
|
||||
@@ -68,7 +68,8 @@ Icmpv4L4Protocol::SendMessage (Ptr<Packet> packet, Ipv4Address dest, uint8_t typ
|
||||
NS_LOG_WARN ("drop icmp message");
|
||||
return;
|
||||
}
|
||||
Ipv4Address source = ipv4->GetAddress (i);
|
||||
// XXX handle multi-address case
|
||||
Ipv4Address source = ipv4->GetAddress (i, 0).GetLocal ();
|
||||
SendMessage (packet, source, dest, type, code);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,10 +219,11 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport,
|
||||
<< " does not match packet dport " << dport);
|
||||
continue;
|
||||
}
|
||||
// XXX handle multi-address case
|
||||
bool isBroadcast = (daddr.IsBroadcast () ||
|
||||
daddr.IsSubnetDirectedBroadcast (
|
||||
incomingInterface->GetNetworkMask ()));
|
||||
Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress ();
|
||||
incomingInterface->GetAddress (0).GetMask ()));
|
||||
Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress (0).GetLocal ();
|
||||
NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast);
|
||||
bool localAddressMatchesWildCard =
|
||||
endP->GetLocalAddress() == Ipv4Address::GetAny();
|
||||
|
||||
@@ -207,28 +207,6 @@ Ipv4Impl::GetNAddresses (uint32_t interface) const
|
||||
return m_ipv4->GetNAddresses (interface);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Impl::SetAddress (uint32_t i, Ipv4Address address)
|
||||
{
|
||||
m_ipv4->SetAddress (i, address);
|
||||
}
|
||||
void
|
||||
Ipv4Impl::SetNetworkMask (uint32_t i, Ipv4Mask mask)
|
||||
{
|
||||
m_ipv4->SetNetworkMask (i, mask);
|
||||
}
|
||||
Ipv4Mask
|
||||
Ipv4Impl::GetNetworkMask (uint32_t i) const
|
||||
{
|
||||
return m_ipv4->GetNetworkMask (i);
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Impl::GetAddress (uint32_t i) const
|
||||
{
|
||||
return m_ipv4->GetAddress (i);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Impl::SetMetric (uint32_t i, uint16_t metric)
|
||||
{
|
||||
@@ -250,21 +228,7 @@ Ipv4Impl::GetInterfaceForDestination (Ipv4Address dest, uint32_t &interface) con
|
||||
Ipv4Address
|
||||
Ipv4Impl::GetSourceAddress (Ipv4Address destination) const
|
||||
{
|
||||
uint32_t interface = 0xffffffff;
|
||||
|
||||
bool result = m_ipv4->GetInterfaceForDestination (destination, interface);
|
||||
|
||||
if (result)
|
||||
{
|
||||
return m_ipv4->GetAddress (interface);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If we can't find any address, just leave it 0.0.0.0
|
||||
//
|
||||
return Ipv4Address::GetAny ();
|
||||
}
|
||||
return m_ipv4->GetSourceAddress (destination);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
||||
@@ -91,10 +91,6 @@ public:
|
||||
Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
|
||||
uint32_t GetNAddresses (uint32_t interface) const;
|
||||
|
||||
virtual void SetAddress (uint32_t i, Ipv4Address address);
|
||||
virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
|
||||
virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
|
||||
virtual Ipv4Address GetAddress (uint32_t i) const;
|
||||
virtual void SetMetric (uint32_t i, uint16_t metric);
|
||||
virtual uint16_t GetMetric (uint32_t i) const;
|
||||
virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const;
|
||||
|
||||
@@ -62,37 +62,6 @@ Ipv4Interface::DoDispose (void)
|
||||
Object::DoDispose ();
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Interface::SetAddress (Ipv4Address a)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << a);
|
||||
m_address = a;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << mask);
|
||||
m_netmask = mask;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Interface::GetBroadcast (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
uint32_t mask = m_netmask.Get ();
|
||||
uint32_t address = m_address.Get ();
|
||||
Ipv4Address broadcast = Ipv4Address (address | (~mask));
|
||||
return broadcast;
|
||||
}
|
||||
|
||||
Ipv4Mask
|
||||
Ipv4Interface::GetNetworkMask (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_netmask;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Interface::SetMetric (uint16_t metric)
|
||||
{
|
||||
@@ -107,13 +76,6 @@ Ipv4Interface::GetMetric (void) const
|
||||
return m_metric;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Interface::GetAddress (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_address;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
Ipv4Interface::GetMtu (void) const
|
||||
{
|
||||
|
||||
@@ -75,23 +75,6 @@ public:
|
||||
*/
|
||||
virtual Ptr<NetDevice> GetDevice (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param a set the ipv4 address of this interface.
|
||||
*/
|
||||
void SetAddress (Ipv4Address a);
|
||||
/**
|
||||
* \param mask set the ipv4 netmask of this interface.
|
||||
*/
|
||||
void SetNetworkMask (Ipv4Mask mask);
|
||||
|
||||
/**
|
||||
* \returns the broadcast ipv4 address associated to this interface
|
||||
*/
|
||||
Ipv4Address GetBroadcast (void) const;
|
||||
/**
|
||||
* \returns the ipv4 netmask of this interface
|
||||
*/
|
||||
Ipv4Mask GetNetworkMask (void) const;
|
||||
/**
|
||||
* \param metric configured routing metric (cost) of this interface
|
||||
*/
|
||||
@@ -100,10 +83,6 @@ public:
|
||||
* \returns configured routing metric (cost) of this interface
|
||||
*/
|
||||
uint16_t GetMetric (void) const;
|
||||
/**
|
||||
* \returns the ipv4 address of this interface
|
||||
*/
|
||||
Ipv4Address GetAddress (void) const;
|
||||
|
||||
/**
|
||||
* This function a pass-through to NetDevice GetMtu, modulo
|
||||
@@ -170,8 +149,6 @@ protected:
|
||||
private:
|
||||
virtual void SendTo (Ptr<Packet> p, Ipv4Address dest) = 0;
|
||||
bool m_ifup;
|
||||
Ipv4Address m_address;
|
||||
Ipv4Mask m_netmask;
|
||||
uint16_t m_metric;
|
||||
|
||||
typedef std::list<Ipv4InterfaceAddress> Ipv4InterfaceAddressList;
|
||||
|
||||
@@ -175,8 +175,8 @@ Ipv4L3Protocol::SetupLoopback (void)
|
||||
|
||||
Ptr<Ipv4LoopbackInterface> interface = CreateObject<Ipv4LoopbackInterface> ();
|
||||
interface->SetNode (m_node);
|
||||
interface->SetAddress (Ipv4Address::GetLoopback ());
|
||||
interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
|
||||
Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
|
||||
interface->AddAddress (ifaceAddr);
|
||||
uint32_t index = AddIpv4Interface (interface);
|
||||
AddHostRouteTo (Ipv4Address::GetLoopback (), index);
|
||||
interface->SetUp ();
|
||||
@@ -437,9 +437,12 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const
|
||||
i != m_interfaces.end ();
|
||||
i++, interface++)
|
||||
{
|
||||
if ((*i)->GetAddress () == addr)
|
||||
for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
|
||||
{
|
||||
return interface;
|
||||
if ((*i)->GetAddress (j).GetLocal () == addr)
|
||||
{
|
||||
return interface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,9 +461,12 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const
|
||||
i != m_interfaces.end ();
|
||||
i++, interface++)
|
||||
{
|
||||
if ((*i)->GetAddress ().CombineMask (mask) == addr.CombineMask (mask))
|
||||
for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
|
||||
{
|
||||
return interface;
|
||||
if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) == addr.CombineMask (mask))
|
||||
{
|
||||
return interface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,11 +648,15 @@ Ipv4L3Protocol::Send (Ptr<Packet> packet,
|
||||
ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
|
||||
{
|
||||
Ptr<Ipv4Interface> outInterface = *ifaceIter;
|
||||
if (destination.IsSubnetDirectedBroadcast (
|
||||
outInterface->GetNetworkMask ()))
|
||||
{
|
||||
ipHeader.SetTtl (1);
|
||||
}
|
||||
// XXX this logic might not be completely correct for multi-addressed interface
|
||||
for (uint32_t j = 0; j < outInterface->GetNAddresses(); j++)
|
||||
{
|
||||
if (destination.IsSubnetDirectedBroadcast (
|
||||
outInterface->GetAddress (j).GetMask ()))
|
||||
{
|
||||
ipHeader.SetTtl (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (destination.IsBroadcast ())
|
||||
@@ -659,9 +669,10 @@ Ipv4L3Protocol::Send (Ptr<Packet> packet,
|
||||
Ptr<Packet> packetCopy = packet->Copy ();
|
||||
|
||||
packetCopy->AddHeader (ipHeader);
|
||||
// XXX Handle multiple address on interface
|
||||
if (packetCopy->GetSize () > outInterface->GetMtu () &&
|
||||
ipHeader.IsDontFragment () &&
|
||||
IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
|
||||
IsUnicast (ipHeader.GetDestination (), outInterface->GetAddress (0).GetMask ()))
|
||||
{
|
||||
Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
|
||||
NS_ASSERT (icmp != 0);
|
||||
@@ -723,9 +734,10 @@ Ipv4L3Protocol::SendRealOut (bool found,
|
||||
NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
|
||||
|
||||
Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
|
||||
// XXX handle multiple address on interface
|
||||
if (packet->GetSize () > outInterface->GetMtu () &&
|
||||
ipHeader.IsDontFragment () &&
|
||||
IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
|
||||
IsUnicast (ipHeader.GetDestination (), outInterface->GetAddress (0).GetMask ()))
|
||||
{
|
||||
NS_LOG_LOGIC ("Too big: need fragmentation but not allowed");
|
||||
Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
|
||||
@@ -788,10 +800,13 @@ Ipv4L3Protocol::Forwarding (
|
||||
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
|
||||
i != m_interfaces.end (); i++)
|
||||
{
|
||||
if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ()))
|
||||
for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
|
||||
{
|
||||
NS_LOG_LOGIC ("For me (destination match)");
|
||||
return false;
|
||||
if ((*i)->GetAddress (j).GetLocal ().IsEqual (ipHeader.GetDestination ()))
|
||||
{
|
||||
NS_LOG_LOGIC ("For me (destination match)");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,7 +816,8 @@ Ipv4L3Protocol::Forwarding (
|
||||
Ptr<Ipv4Interface> interface = *i;
|
||||
if (interface->GetDevice () == device)
|
||||
{
|
||||
if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ()))
|
||||
// XXX multi-address case
|
||||
if (ipHeader.GetDestination ().IsEqual (interface->GetAddress (0).GetBroadcast ()))
|
||||
{
|
||||
NS_LOG_LOGIC ("For me (interface broadcast address)");
|
||||
return false;
|
||||
@@ -852,9 +868,10 @@ Ipv4L3Protocol::DoForward (uint32_t interface,
|
||||
NS_LOG_FUNCTION (this << interface << packet << ipHeader);
|
||||
|
||||
ipHeader.SetTtl (ipHeader.GetTtl () - 1);
|
||||
// XXX handle multi-interfaces
|
||||
if (ipHeader.GetTtl () == 0)
|
||||
{
|
||||
if (IsUnicast (ipHeader.GetDestination (), GetInterface (interface)->GetNetworkMask ()))
|
||||
if (IsUnicast (ipHeader.GetDestination (), GetInterface (interface)->GetAddress (0).GetMask ()))
|
||||
{
|
||||
Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
|
||||
icmp->SendTimeExceededTtl (ipHeader, packet);
|
||||
@@ -889,7 +906,8 @@ Ipv4L3Protocol::ForwardUp (Ptr<Packet> p, Ipv4Header const&ip,
|
||||
case Ipv4L4Protocol::RX_CSUM_FAILED:
|
||||
break;
|
||||
case Ipv4L4Protocol::RX_ENDPOINT_UNREACH:
|
||||
if (IsUnicast (ip.GetDestination (), incomingInterface->GetNetworkMask ()))
|
||||
// XXX handle multi-interface case
|
||||
if (IsUnicast (ip.GetDestination (), incomingInterface->GetAddress (0).GetMask ()))
|
||||
{
|
||||
GetIcmp ()->SendDestUnreachPort (ip, copy);
|
||||
}
|
||||
@@ -947,38 +965,6 @@ Ipv4L3Protocol::GetNAddresses (uint32_t interface) const
|
||||
return iface->GetNAddresses ();
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << i << address);
|
||||
Ptr<Ipv4Interface> interface = GetInterface (i);
|
||||
interface->SetAddress (address);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << i << mask);
|
||||
Ptr<Ipv4Interface> interface = GetInterface (i);
|
||||
interface->SetNetworkMask (mask);
|
||||
}
|
||||
|
||||
Ipv4Mask
|
||||
Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this << i);
|
||||
Ptr<Ipv4Interface> interface = GetInterface (i);
|
||||
return interface->GetNetworkMask ();
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4L3Protocol::GetAddress (uint32_t i) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this << i);
|
||||
Ptr<Ipv4Interface> interface = GetInterface (i);
|
||||
return interface->GetAddress ();
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
|
||||
{
|
||||
@@ -1091,11 +1077,13 @@ Ipv4L3Protocol::SetUp (uint32_t i)
|
||||
// If interface address and network mask have been set, add a route
|
||||
// to the network of the interface (like e.g. ifconfig does on a
|
||||
// Linux box)
|
||||
if (((interface->GetAddress ()) != (Ipv4Address ()))
|
||||
&& (interface->GetNetworkMask ()) != (Ipv4Mask ()))
|
||||
for (uint32_t j = 0; j < interface->GetNAddresses (); j++)
|
||||
{
|
||||
AddNetworkRouteTo (interface->GetAddress ().CombineMask (interface->GetNetworkMask ()),
|
||||
interface->GetNetworkMask (), i);
|
||||
if (((interface->GetAddress (j).GetLocal ()) != (Ipv4Address ()))
|
||||
&& (interface->GetAddress (j).GetMask ()) != (Ipv4Mask ()))
|
||||
{
|
||||
AddNetworkRouteTo (interface->GetAddress (j).GetLocal ().CombineMask (interface->GetAddress (j).GetMask ()), interface->GetAddress (j).GetMask (), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1124,4 +1112,36 @@ Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Note: This method will be removed in Ipv4 routing work
|
||||
Ipv4Address
|
||||
Ipv4L3Protocol::GetSourceAddress (Ipv4Address destination) const
|
||||
{
|
||||
uint32_t interface = 0xffffffff;
|
||||
|
||||
bool result = GetInterfaceForDestination (destination, interface);
|
||||
|
||||
if (result)
|
||||
{
|
||||
// if multiple addresses exist, search for the first one on the same subnet
|
||||
for (uint32_t i = 0; i < GetNAddresses (interface); i++)
|
||||
{
|
||||
Ipv4InterfaceAddress ipv4InAddr = GetAddress (interface, i);
|
||||
if (ipv4InAddr.GetLocal().CombineMask(ipv4InAddr.GetMask ()) == destination.CombineMask (ipv4InAddr.GetMask ()))
|
||||
{
|
||||
return ipv4InAddr.GetLocal ();
|
||||
}
|
||||
}
|
||||
// Destination is off-link, so return first address.
|
||||
return GetAddress (interface, 0).GetLocal ();
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If we can't find any address, just leave it 0.0.0.0
|
||||
//
|
||||
return Ipv4Address::GetAny ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -191,12 +191,9 @@ public:
|
||||
Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
|
||||
uint32_t GetNAddresses (uint32_t interface) const;
|
||||
|
||||
void SetAddress (uint32_t i, Ipv4Address address);
|
||||
void SetNetworkMask (uint32_t i, Ipv4Mask mask);
|
||||
Ipv4Mask GetNetworkMask (uint32_t t) const;
|
||||
Ipv4Address GetAddress (uint32_t i) const;
|
||||
void SetMetric (uint32_t i, uint16_t metric);
|
||||
uint16_t GetMetric (uint32_t i) const;
|
||||
Ipv4Address GetSourceAddress (Ipv4Address destination) const;
|
||||
bool GetInterfaceForDestination (Ipv4Address destination,
|
||||
uint32_t& interface) const;
|
||||
uint16_t GetMtu (uint32_t i) const;
|
||||
|
||||
@@ -173,7 +173,7 @@ Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags,
|
||||
uint32_t localInterface;
|
||||
if (ipv4->GetInterfaceForDestination(dst, localInterface))
|
||||
{
|
||||
ipv4->Send (p, ipv4->GetAddress (localInterface), dst, m_protocol);
|
||||
ipv4->Send (p, ipv4->GetSourceAddress (dst), dst, m_protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -344,8 +344,9 @@ void NscTcpL4Protocol::AddInterface(void)
|
||||
// how things _should_ be (once nsc can deal with multiple interfaces...)
|
||||
for (uint32_t i = 1; i < nInterfaces; i++)
|
||||
{
|
||||
Ipv4Address addr = ip->GetAddress(i);
|
||||
Ipv4Mask mask = ip->GetNetworkMask(i);
|
||||
Ipv4InterfaceAddress ifAddr = ip->GetAddress (i, 0);
|
||||
Ipv4Address addr = ifAddr.GetLocal ();
|
||||
Ipv4Mask mask = ifAddr.GetMask ();
|
||||
uint16_t mtu = ip->GetMtu (i);
|
||||
|
||||
std::ostringstream addrOss, maskOss;
|
||||
|
||||
@@ -345,7 +345,7 @@ TcpSocketImpl::Connect (const Address & address)
|
||||
|
||||
if (ipv4->GetInterfaceForDestination (m_remoteAddress, localInterface))
|
||||
{
|
||||
m_endPoint->SetLocalAddress (ipv4->GetAddress (localInterface));
|
||||
m_endPoint->SetLocalAddress (ipv4->GetSourceAddress (m_remoteAddress));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -832,7 +832,7 @@ bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
|
||||
m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
|
||||
if (ipv4->GetInterfaceForDestination (m_remoteAddress, localInterface))
|
||||
{
|
||||
m_localAddress = ipv4->GetAddress (localInterface);
|
||||
m_localAddress = ipv4->GetSourceAddress (m_remoteAddress);
|
||||
m_endPoint->SetLocalAddress (m_localAddress);
|
||||
// Leave local addr in the portmap to any, as the path from
|
||||
// remote can change and packets can arrive on different interfaces
|
||||
@@ -1930,8 +1930,8 @@ TcpSocketImplTest::AddSimpleNetDevice (Ptr<Node> node, const char* ipaddr, const
|
||||
node->AddDevice (dev);
|
||||
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
|
||||
uint32_t ndid = ipv4->AddInterface (dev);
|
||||
ipv4->SetAddress (ndid, Ipv4Address (ipaddr));
|
||||
ipv4->SetNetworkMask (ndid, Ipv4Mask (netmask));
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address (ipaddr), Ipv4Mask (netmask));
|
||||
ipv4->AddAddress (ndid, ipv4Addr);
|
||||
ipv4->SetUp (ndid);
|
||||
return dev;
|
||||
}
|
||||
|
||||
@@ -362,8 +362,10 @@ UdpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address dest, uint16_t port)
|
||||
NS_LOG_LOGIC ("Limited broadcast start.");
|
||||
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
|
||||
{
|
||||
Ipv4Address addri = ipv4->GetAddress (i);
|
||||
Ipv4Mask maski = ipv4->GetNetworkMask (i);
|
||||
// Get the primary address
|
||||
Ipv4InterfaceAddress iaddr = ipv4->GetAddress (i, 0);
|
||||
Ipv4Address addri = iaddr.GetLocal ();
|
||||
Ipv4Mask maski = iaddr.GetMask ();
|
||||
if (maski == Ipv4Mask::GetOnes ())
|
||||
{
|
||||
// if the network mask is 255.255.255.255, do not convert dest
|
||||
@@ -392,7 +394,7 @@ UdpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address dest, uint16_t port)
|
||||
else if (ipv4->GetInterfaceForDestination(dest, localInterface))
|
||||
{
|
||||
NS_LOG_LOGIC ("Route exists");
|
||||
m_udp->Send (p->Copy (), ipv4->GetAddress (localInterface), dest,
|
||||
m_udp->Send (p->Copy (), ipv4->GetSourceAddress (dest), dest,
|
||||
m_endPoint->GetLocalPort (), port);
|
||||
NotifyDataSent (p->GetSize ());
|
||||
NotifySend (GetTxAvailable ());
|
||||
@@ -666,8 +668,8 @@ UdpSocketImplTest::RunTests (void)
|
||||
rxNode->AddDevice (rxDev1);
|
||||
Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
|
||||
uint32_t netdev_idx = ipv4->AddInterface (rxDev1);
|
||||
ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.0.1"));
|
||||
ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask (0xffff0000U));
|
||||
ipv4->AddAddress (netdev_idx, ipv4Addr);
|
||||
ipv4->SetUp (netdev_idx);
|
||||
}
|
||||
|
||||
@@ -677,8 +679,8 @@ UdpSocketImplTest::RunTests (void)
|
||||
rxNode->AddDevice (rxDev2);
|
||||
Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
|
||||
uint32_t netdev_idx = ipv4->AddInterface (rxDev2);
|
||||
ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.1.1"));
|
||||
ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask (0xffff0000U));
|
||||
ipv4->AddAddress (netdev_idx, ipv4Addr);
|
||||
ipv4->SetUp (netdev_idx);
|
||||
}
|
||||
|
||||
@@ -692,8 +694,8 @@ UdpSocketImplTest::RunTests (void)
|
||||
txNode->AddDevice (txDev1);
|
||||
Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
|
||||
uint32_t netdev_idx = ipv4->AddInterface (txDev1);
|
||||
ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.0.2"));
|
||||
ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask (0xffff0000U));
|
||||
ipv4->AddAddress (netdev_idx, ipv4Addr);
|
||||
ipv4->SetUp (netdev_idx);
|
||||
}
|
||||
Ptr<SimpleNetDevice> txDev2;
|
||||
@@ -703,8 +705,8 @@ UdpSocketImplTest::RunTests (void)
|
||||
txNode->AddDevice (txDev2);
|
||||
Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
|
||||
uint32_t netdev_idx = ipv4->AddInterface (txDev2);
|
||||
ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.1.2"));
|
||||
ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
|
||||
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask (0xffff0000U));
|
||||
ipv4->AddAddress (netdev_idx, ipv4Addr);
|
||||
ipv4->SetUp (netdev_idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,13 @@ Ipv4::GetInterfaceByAddress (Ipv4Address addr, Ipv4Mask mask)
|
||||
{
|
||||
for (uint32_t i = 0; i < GetNInterfaces (); i++)
|
||||
{
|
||||
if (GetAddress (i).CombineMask(mask) == addr.CombineMask(mask) )
|
||||
for (uint32_t j = 0; j < GetNAddresses (i); j++)
|
||||
{
|
||||
return i;
|
||||
Ipv4InterfaceAddress ipv4InAddr = GetAddress (i, j);
|
||||
if (ipv4InAddr.GetLocal ().CombineMask(mask) == addr.CombineMask(mask) )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mapping not found
|
||||
|
||||
@@ -411,24 +411,6 @@ public:
|
||||
*/
|
||||
virtual Ipv4InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param address address to associate to the underlying ipv4 interface
|
||||
*/
|
||||
virtual void SetAddress (uint32_t i, Ipv4Address address) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param mask mask to associate to the underlying ipv4 interface
|
||||
*/
|
||||
virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \returns the mask associated to the underlying ipv4 interface
|
||||
*/
|
||||
virtual Ipv4Mask GetNetworkMask (uint32_t i) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param metric routing metric (cost) associated to the underlying
|
||||
@@ -443,17 +425,6 @@ public:
|
||||
*/
|
||||
virtual uint16_t GetMetric (uint32_t i) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \returns the address associated to the underlying ipv4 interface
|
||||
*
|
||||
* Note that the broadcast address for this interface may be fetched
|
||||
* from the Ipv4Address object returned here using
|
||||
* Ipv4Address::GetSubnetDirectedBroadcast(mask), where the mask for
|
||||
* the interface may be retrived using Ipv4::GetNetworkMask(i).
|
||||
*/
|
||||
virtual Ipv4Address GetAddress (uint32_t i) const = 0;
|
||||
|
||||
/**
|
||||
* \param destination The IP address of a hypothetical destination.
|
||||
* \returns The IP address assigned to the interface that will be used
|
||||
|
||||
@@ -704,8 +704,12 @@ GlobalRouter::ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *p
|
||||
Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
|
||||
NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
|
||||
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
|
||||
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
|
||||
if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
|
||||
Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
|
||||
NS_LOG_LOGIC ("Working with local address " << addrLocal);
|
||||
uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
|
||||
|
||||
@@ -820,8 +824,12 @@ GlobalRouter::ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *
|
||||
Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
|
||||
NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
|
||||
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
|
||||
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
|
||||
if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
|
||||
Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();;
|
||||
NS_LOG_LOGIC ("Working with local address " << addrLocal);
|
||||
uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
|
||||
|
||||
@@ -962,8 +970,12 @@ GlobalRouter::ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA
|
||||
Ptr<Ipv4> ipv4Local = nodeLocal->GetObject<Ipv4> ();
|
||||
NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
|
||||
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
|
||||
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
|
||||
if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
|
||||
Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
|
||||
NS_LOG_LOGIC ("Working with local address " << addrLocal);
|
||||
uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
|
||||
|
||||
@@ -1018,8 +1030,12 @@ GlobalRouter::ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA
|
||||
// Now that we have the Ipv4 interface, we can get the (remote) address and
|
||||
// mask we need.
|
||||
//
|
||||
Ipv4Address addrRemote = ipv4Remote->GetAddress(interfaceRemote);
|
||||
Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(interfaceRemote);
|
||||
if (ipv4Remote->GetNAddresses (interfaceRemote) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrRemote = ipv4Remote->GetAddress (interfaceRemote, 0).GetLocal ();
|
||||
Ipv4Mask maskRemote = ipv4Remote->GetAddress (interfaceRemote, 0).GetMask ();
|
||||
NS_LOG_LOGIC ("Working with remote address " << addrRemote);
|
||||
|
||||
//
|
||||
@@ -1076,8 +1092,12 @@ GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c)
|
||||
Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
|
||||
NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
|
||||
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
|
||||
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
|
||||
if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
|
||||
Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
|
||||
|
||||
GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
|
||||
NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
|
||||
@@ -1128,7 +1148,11 @@ GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c)
|
||||
}
|
||||
else
|
||||
{
|
||||
Ipv4Address tempAddr = tempIpv4->GetAddress(tempInterface);
|
||||
if (tempIpv4->GetNAddresses (tempInterface) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address tempAddr = tempIpv4->GetAddress(tempInterface, 0).GetLocal ();
|
||||
pLSA->AddAttachedRouter (tempAddr);
|
||||
}
|
||||
}
|
||||
@@ -1206,7 +1230,11 @@ GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRec
|
||||
NS_LOG_LOGIC ("Remote side interface " << interfaceOther << " not up");
|
||||
continue;
|
||||
}
|
||||
Ipv4Address addrOther = ipv4->GetAddress (interfaceOther);
|
||||
if (ipv4->GetNAddresses (interfaceOther) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
|
||||
desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
|
||||
NS_LOG_LOGIC ("designated router now " << desigRtr);
|
||||
}
|
||||
@@ -1255,7 +1283,11 @@ GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRec
|
||||
continue;
|
||||
}
|
||||
NS_LOG_LOGIC ("Found router on net device " << ndOther);
|
||||
Ipv4Address addrOther = ipv4->GetAddress (interfaceOther);
|
||||
if (ipv4->GetNAddresses (interfaceOther) > 1)
|
||||
{
|
||||
NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
|
||||
}
|
||||
Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
|
||||
desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
|
||||
NS_LOG_LOGIC ("designated router now " << desigRtr);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,8 @@ void AgentImpl::Start ()
|
||||
Ipv4Address loopback ("127.0.0.1");
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
|
||||
{
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i);
|
||||
// Use primary address, if multiple
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
|
||||
if (addr != loopback)
|
||||
{
|
||||
m_mainAddress = addr;
|
||||
@@ -260,7 +261,7 @@ void AgentImpl::Start ()
|
||||
Ipv4Address loopback ("127.0.0.1");
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
|
||||
{
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i);
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
|
||||
if (addr == loopback)
|
||||
continue;
|
||||
|
||||
@@ -297,7 +298,7 @@ void AgentImpl::Start ()
|
||||
|
||||
void AgentImpl::SetMainInterface (uint32_t interface)
|
||||
{
|
||||
m_mainAddress = m_ipv4->GetAddress (interface);
|
||||
m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
|
||||
}
|
||||
|
||||
|
||||
@@ -1556,7 +1557,7 @@ AgentImpl::SendMid ()
|
||||
Ipv4Address loopback ("127.0.0.1");
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
|
||||
{
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i);
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
|
||||
if (addr != m_mainAddress && addr != loopback)
|
||||
mid.interfaceAddresses.push_back (addr);
|
||||
}
|
||||
|
||||
@@ -210,10 +210,13 @@ RoutingTable::AddEntry (Ipv4Address const &dest,
|
||||
RoutingTableEntry entry;
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
|
||||
{
|
||||
if (m_ipv4->GetAddress (i) == interfaceAddress)
|
||||
for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
|
||||
{
|
||||
AddEntry (dest, next, i, distance);
|
||||
return;
|
||||
if (m_ipv4->GetAddress (i,j).GetLocal () == interfaceAddress)
|
||||
{
|
||||
AddEntry (dest, next, i, distance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_ASSERT (false); // should not be reached
|
||||
|
||||
Reference in New Issue
Block a user