internet: Move SourceAddressSelection from Ipv4StaticRouting to Ipv4
This commit is contained in:
@@ -1124,6 +1124,33 @@ Ipv4L3Protocol::RemoveAddress (uint32_t i, Ipv4Address address)
|
||||
return false;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4L3Protocol::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << interfaceIdx << " " << dest);
|
||||
if (GetNAddresses (interfaceIdx) == 1) // common case
|
||||
{
|
||||
return GetAddress (interfaceIdx, 0).GetLocal ();
|
||||
}
|
||||
// no way to determine the scope of the destination, so adopt the
|
||||
// following rule: pick the first available address (index 0) unless
|
||||
// a subsequent address is on link (in which case, pick the primary
|
||||
// address if there are multiple)
|
||||
Ipv4Address candidate = GetAddress (interfaceIdx, 0).GetLocal ();
|
||||
for (uint32_t i = 0; i < GetNAddresses (interfaceIdx); i++)
|
||||
{
|
||||
Ipv4InterfaceAddress test = GetAddress (interfaceIdx, i);
|
||||
if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.CombineMask (test.GetMask ()))
|
||||
{
|
||||
if (test.IsSecondary () == false)
|
||||
{
|
||||
return test.GetLocal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4L3Protocol::SelectSourceAddress (Ptr<const NetDevice> device,
|
||||
Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
|
||||
|
||||
@@ -144,22 +144,8 @@ public:
|
||||
*/
|
||||
void Insert (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
|
||||
|
||||
/**
|
||||
* \param protocolNumber number of protocol to lookup
|
||||
* in this L4 Demux
|
||||
* \returns a matching L4 Protocol
|
||||
*
|
||||
* This method is typically called by lower layers
|
||||
* to forward packets up the stack to the right protocol.
|
||||
*/
|
||||
virtual Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest);
|
||||
virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
|
||||
|
||||
/**
|
||||
* \brief Get L4 protocol by protocol number for the specified interface.
|
||||
* \param protocolNumber protocol number
|
||||
* \param interfaceIndex interface index, -1 means "any" interface.
|
||||
* \return corresponding IpL4Protocol or 0 if not found
|
||||
*/
|
||||
virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber, int32_t interfaceIndex) const;
|
||||
|
||||
/**
|
||||
@@ -194,7 +180,7 @@ public:
|
||||
* \param device network device
|
||||
* \param p the packet
|
||||
* \param protocol protocol value
|
||||
* \param from address of the correspondant
|
||||
* \param from address of the correspondent
|
||||
* \param to address of the destination
|
||||
* \param packetType type of the packet
|
||||
*/
|
||||
|
||||
@@ -235,7 +235,7 @@ Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
|
||||
rtentry->SetDestination (dest);
|
||||
rtentry->SetGateway (Ipv4Address::GetZero ());
|
||||
rtentry->SetOutputDevice (oif);
|
||||
rtentry->SetSource (m_ipv4->GetAddress (oif->GetIfIndex (), 0).GetLocal ());
|
||||
rtentry->SetSource (m_ipv4->GetAddress (m_ipv4->GetInterfaceForDevice (oif), 0).GetLocal ());
|
||||
return rtentry;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
|
||||
uint32_t interfaceIdx = route->GetInterface ();
|
||||
rtentry = Create<Ipv4Route> ();
|
||||
rtentry->SetDestination (route->GetDest ());
|
||||
rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
|
||||
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
|
||||
rtentry->SetGateway (route->GetGateway ());
|
||||
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
|
||||
if (masklen == 32)
|
||||
@@ -741,31 +741,5 @@ Ipv4StaticRouting::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
|
||||
}
|
||||
*os << std::endl;
|
||||
}
|
||||
Ipv4Address
|
||||
Ipv4StaticRouting::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << interfaceIdx << " " << dest);
|
||||
if (m_ipv4->GetNAddresses (interfaceIdx) == 1) // common case
|
||||
{
|
||||
return m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
|
||||
}
|
||||
// no way to determine the scope of the destination, so adopt the
|
||||
// following rule: pick the first available address (index 0) unless
|
||||
// a subsequent address is on link (in which case, pick the primary
|
||||
// address if there are multiple)
|
||||
Ipv4Address candidate = m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNAddresses (interfaceIdx); i++)
|
||||
{
|
||||
Ipv4InterfaceAddress test = m_ipv4->GetAddress (interfaceIdx, i);
|
||||
if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.CombineMask (test.GetMask ()))
|
||||
{
|
||||
if (test.IsSecondary () == false)
|
||||
{
|
||||
return test.GetLocal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -417,14 +417,6 @@ private:
|
||||
Ptr<Ipv4MulticastRoute> LookupStatic (Ipv4Address origin, Ipv4Address group,
|
||||
uint32_t interface);
|
||||
|
||||
/**
|
||||
* \brief Choose the source address to use with destination address.
|
||||
* \param interface interface index
|
||||
* \param dest IPv4 destination address
|
||||
* \return IPv4 source address to use
|
||||
*/
|
||||
Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest);
|
||||
|
||||
/**
|
||||
* \brief the forwarding table for network.
|
||||
*/
|
||||
|
||||
@@ -359,6 +359,14 @@ public:
|
||||
*/
|
||||
virtual void SetForwarding (uint32_t interface, bool val) = 0;
|
||||
|
||||
/**
|
||||
* \brief Choose the source address to use with destination address.
|
||||
* \param interface interface index
|
||||
* \param dest IPv4 destination address
|
||||
* \return IPv4 source address to use
|
||||
*/
|
||||
virtual Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest) = 0;
|
||||
|
||||
/**
|
||||
* \param protocolNumber number of protocol to lookup
|
||||
* in this L4 Demux
|
||||
@@ -369,6 +377,14 @@ public:
|
||||
*/
|
||||
virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Get L4 protocol by protocol number for the specified interface.
|
||||
* \param protocolNumber protocol number
|
||||
* \param interfaceIndex interface index, -1 means "any" interface.
|
||||
* \return corresponding IpL4Protocol or 0 if not found
|
||||
*/
|
||||
virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber, int32_t interfaceIndex) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Creates a raw socket
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user