|
|
| 20 |
#include <iomanip> |
20 |
#include <iomanip> |
| 21 |
#include "ns3/names.h" |
21 |
#include "ns3/names.h" |
| 22 |
#include "ns3/log.h" |
22 |
#include "ns3/log.h" |
|
|
23 |
#include "ns3/abort.h" |
| 23 |
#include "ns3/simulator.h" |
24 |
#include "ns3/simulator.h" |
| 24 |
#include "ns3/object.h" |
25 |
#include "ns3/object.h" |
| 25 |
#include "ns3/packet.h" |
26 |
#include "ns3/packet.h" |
|
|
| 27 |
#include "ns3/ipv4-route.h" |
28 |
#include "ns3/ipv4-route.h" |
| 28 |
#include "ns3/ipv4-routing-table-entry.h" |
29 |
#include "ns3/ipv4-routing-table-entry.h" |
| 29 |
#include "ns3/boolean.h" |
30 |
#include "ns3/boolean.h" |
|
|
31 |
#include "udp-header.h" |
| 32 |
#include "tcp-header.h" |
| 30 |
#include "ipv4-global-routing.h" |
33 |
#include "ipv4-global-routing.h" |
| 31 |
#include "global-route-manager.h" |
34 |
#include "global-route-manager.h" |
| 32 |
|
35 |
|
|
|
| 36 |
|
39 |
|
| 37 |
NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting); |
40 |
NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting); |
| 38 |
|
41 |
|
|
|
42 |
/* see http://www.iana.org/assignments/protocol-numbers */ |
| 43 |
const uint8_t TCP_PROT_NUMBER = 6; |
| 44 |
const uint8_t UDP_PROT_NUMBER = 17; |
| 45 |
|
| 39 |
TypeId |
46 |
TypeId |
| 40 |
Ipv4GlobalRouting::GetTypeId (void) |
47 |
Ipv4GlobalRouting::GetTypeId (void) |
| 41 |
{ |
48 |
{ |
|
|
| 46 |
BooleanValue (false), |
53 |
BooleanValue (false), |
| 47 |
MakeBooleanAccessor (&Ipv4GlobalRouting::m_randomEcmpRouting), |
54 |
MakeBooleanAccessor (&Ipv4GlobalRouting::m_randomEcmpRouting), |
| 48 |
MakeBooleanChecker ()) |
55 |
MakeBooleanChecker ()) |
|
|
56 |
.AddAttribute ("FlowEcmpRouting", |
| 57 |
"Set to true if flows are randomly routed among ECMP; set to false for using only one route consistently", |
| 58 |
BooleanValue (false), |
| 59 |
MakeBooleanAccessor (&Ipv4GlobalRouting::m_flowEcmpRouting), |
| 60 |
MakeBooleanChecker ()) |
| 49 |
.AddAttribute ("RespondToInterfaceEvents", |
61 |
.AddAttribute ("RespondToInterfaceEvents", |
| 50 |
"Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)", |
62 |
"Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)", |
| 51 |
BooleanValue (false), |
63 |
BooleanValue (false), |
|
|
| 57 |
|
69 |
|
| 58 |
Ipv4GlobalRouting::Ipv4GlobalRouting () |
70 |
Ipv4GlobalRouting::Ipv4GlobalRouting () |
| 59 |
: m_randomEcmpRouting (false), |
71 |
: m_randomEcmpRouting (false), |
|
|
72 |
m_flowEcmpRouting (false), |
| 60 |
m_respondToInterfaceEvents (false) |
73 |
m_respondToInterfaceEvents (false) |
| 61 |
{ |
74 |
{ |
| 62 |
NS_LOG_FUNCTION_NOARGS (); |
75 |
NS_LOG_FUNCTION_NOARGS (); |
|
|
| 133 |
m_ASexternalRoutes.push_back (route); |
146 |
m_ASexternalRoutes.push_back (route); |
| 134 |
} |
147 |
} |
| 135 |
|
148 |
|
|
|
149 |
// This function is used to spread the routing of flows across equal |
| 150 |
// cost paths, by calculating an integer based on the five-tuple in the headers |
| 151 |
// |
| 152 |
// It assumes that if a transport protocol value is specified in the header, |
| 153 |
// that a transport header with port numbers is prepended to the ipPayload |
| 154 |
// |
| 155 |
uint32_t |
| 156 |
Ipv4GlobalRouting::GetTupleValue (const Ipv4Header &header, Ptr<const Packet> ipPayload) |
| 157 |
{ |
| 158 |
// We do not care if this value rolls over |
| 159 |
uint32_t tupleValue = header.GetSource ().Get () + |
| 160 |
header.GetDestination ().Get () + |
| 161 |
header.GetProtocol (); |
| 162 |
switch (header.GetProtocol ()) |
| 163 |
{ |
| 164 |
case UDP_PROT_NUMBER: |
| 165 |
{ |
| 166 |
UdpHeader udpHeader; |
| 167 |
ipPayload->PeekHeader (udpHeader); |
| 168 |
NS_LOG_DEBUG ("Found UDP proto and header: " << |
| 169 |
udpHeader.GetSourcePort () << ":" << |
| 170 |
udpHeader.GetDestinationPort ()); |
| 171 |
tupleValue += udpHeader.GetSourcePort (); |
| 172 |
tupleValue += udpHeader.GetDestinationPort (); |
| 173 |
break; |
| 174 |
} |
| 175 |
case TCP_PROT_NUMBER: |
| 176 |
{ |
| 177 |
TcpHeader tcpHeader; |
| 178 |
ipPayload->PeekHeader (tcpHeader); |
| 179 |
NS_LOG_DEBUG ("Found TCP proto and header: " << |
| 180 |
tcpHeader.GetSourcePort () << ":" << |
| 181 |
tcpHeader.GetDestinationPort ()); |
| 182 |
tupleValue += tcpHeader.GetSourcePort (); |
| 183 |
tupleValue += tcpHeader.GetDestinationPort (); |
| 184 |
break; |
| 185 |
} |
| 186 |
default: |
| 187 |
{ |
| 188 |
NS_LOG_DEBUG ("Udp or Tcp header not found"); |
| 189 |
break; |
| 190 |
} |
| 191 |
} |
| 192 |
return tupleValue; |
| 193 |
} |
| 136 |
|
194 |
|
| 137 |
Ptr<Ipv4Route> |
195 |
Ptr<Ipv4Route> |
| 138 |
Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest, Ptr<NetDevice> oif) |
196 |
Ipv4GlobalRouting::LookupGlobal (const Ipv4Header &header, Ptr<const Packet> ipPayload, Ptr<NetDevice> oif) |
| 139 |
{ |
197 |
{ |
| 140 |
NS_LOG_FUNCTION_NOARGS (); |
198 |
NS_LOG_FUNCTION_NOARGS (); |
| 141 |
NS_LOG_LOGIC ("Looking for route for destination " << dest); |
199 |
NS_ABORT_MSG_IF (m_randomEcmpRouting && m_flowEcmpRouting, "Ecmp mode selection"); |
|
|
200 |
NS_LOG_LOGIC ("Looking for route for destination " << header.GetDestination()); |
| 142 |
Ptr<Ipv4Route> rtentry = 0; |
201 |
Ptr<Ipv4Route> rtentry = 0; |
| 143 |
// store all available routes that bring packets to their destination |
202 |
// store all available routes that bring packets to their destination |
| 144 |
typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t; |
203 |
typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t; |
|
|
| 150 |
i++) |
209 |
i++) |
| 151 |
{ |
210 |
{ |
| 152 |
NS_ASSERT ((*i)->IsHost ()); |
211 |
NS_ASSERT ((*i)->IsHost ()); |
| 153 |
if ((*i)->GetDest ().IsEqual (dest)) |
212 |
if ((*i)->GetDest ().IsEqual (header.GetDestination ())) |
| 154 |
{ |
213 |
{ |
| 155 |
if (oif != 0) |
214 |
if (oif != 0) |
| 156 |
{ |
215 |
{ |
|
|
| 173 |
{ |
232 |
{ |
| 174 |
Ipv4Mask mask = (*j)->GetDestNetworkMask (); |
233 |
Ipv4Mask mask = (*j)->GetDestNetworkMask (); |
| 175 |
Ipv4Address entry = (*j)->GetDestNetwork (); |
234 |
Ipv4Address entry = (*j)->GetDestNetwork (); |
| 176 |
if (mask.IsMatch (dest, entry)) |
235 |
if (mask.IsMatch (header.GetDestination (), entry)) |
| 177 |
{ |
236 |
{ |
| 178 |
if (oif != 0) |
237 |
if (oif != 0) |
| 179 |
{ |
238 |
{ |
|
|
| 196 |
{ |
255 |
{ |
| 197 |
Ipv4Mask mask = (*k)->GetDestNetworkMask (); |
256 |
Ipv4Mask mask = (*k)->GetDestNetworkMask (); |
| 198 |
Ipv4Address entry = (*k)->GetDestNetwork (); |
257 |
Ipv4Address entry = (*k)->GetDestNetwork (); |
| 199 |
if (mask.IsMatch (dest, entry)) |
258 |
if (mask.IsMatch (header.GetDestination (), entry)) |
| 200 |
{ |
259 |
{ |
| 201 |
NS_LOG_LOGIC ("Found external route" << *k); |
260 |
NS_LOG_LOGIC ("Found external route" << *k); |
| 202 |
if (oif != 0) |
261 |
if (oif != 0) |
|
|
| 214 |
} |
273 |
} |
| 215 |
if (allRoutes.size () > 0 ) // if route(s) is found |
274 |
if (allRoutes.size () > 0 ) // if route(s) is found |
| 216 |
{ |
275 |
{ |
| 217 |
// pick up one of the routes uniformly at random if random |
276 |
// select one of the routes uniformly at random if random |
| 218 |
// ECMP routing is enabled, or always select the first route |
277 |
// ECMP routing is enabled, or map a flow consistently to a route |
| 219 |
// consistently if random ECMP routing is disabled |
278 |
// if flow ECMP routing is enabled, or otherwise always select the |
|
|
279 |
// first route |
| 220 |
uint32_t selectIndex; |
280 |
uint32_t selectIndex; |
| 221 |
if (m_randomEcmpRouting) |
281 |
if (m_randomEcmpRouting) |
| 222 |
{ |
282 |
{ |
| 223 |
selectIndex = m_rand->GetInteger (0, allRoutes.size ()-1); |
283 |
selectIndex = m_rand->GetInteger (0, allRoutes.size ()-1); |
| 224 |
} |
284 |
} |
| 225 |
else |
285 |
else if (m_flowEcmpRouting && (allRoutes.size () > 1)) |
|
|
286 |
{ |
| 287 |
selectIndex = GetTupleValue (header, ipPayload) % allRoutes.size (); |
| 288 |
} |
| 289 |
else |
| 226 |
{ |
290 |
{ |
| 227 |
selectIndex = 0; |
291 |
selectIndex = 0; |
| 228 |
} |
292 |
} |
|
|
| 458 |
// See if this is a unicast packet we have a route for. |
522 |
// See if this is a unicast packet we have a route for. |
| 459 |
// |
523 |
// |
| 460 |
NS_LOG_LOGIC ("Unicast destination- looking up"); |
524 |
NS_LOG_LOGIC ("Unicast destination- looking up"); |
| 461 |
Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination (), oif); |
525 |
Ptr<Ipv4Route> rtentry = LookupGlobal (header, p, oif); |
| 462 |
if (rtentry) |
526 |
if (rtentry) |
| 463 |
{ |
527 |
{ |
| 464 |
sockerr = Socket::ERROR_NOTERROR; |
528 |
sockerr = Socket::ERROR_NOTERROR; |
|
|
| 536 |
} |
600 |
} |
| 537 |
// Next, try to find a route |
601 |
// Next, try to find a route |
| 538 |
NS_LOG_LOGIC ("Unicast destination- looking up global route"); |
602 |
NS_LOG_LOGIC ("Unicast destination- looking up global route"); |
| 539 |
Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination ()); |
603 |
Ptr<Ipv4Route> rtentry = LookupGlobal (header, p); |
| 540 |
if (rtentry != 0) |
604 |
if (rtentry != 0) |
| 541 |
{ |
605 |
{ |
| 542 |
NS_LOG_LOGIC ("Found unicast destination- calling unicast callback"); |
606 |
NS_LOG_LOGIC ("Found unicast destination- calling unicast callback"); |