equal
deleted
inserted
replaced
24 #include "ns3/boolean.h" |
24 #include "ns3/boolean.h" |
25 #include "ns3/object-vector.h" |
25 #include "ns3/object-vector.h" |
26 |
26 |
27 #include "ns3/packet.h" |
27 #include "ns3/packet.h" |
28 #include "ns3/node.h" |
28 #include "ns3/node.h" |
|
29 #include "ns3/ipv4-route.h" |
29 |
30 |
30 #include "tcp-l4-protocol.h" |
31 #include "tcp-l4-protocol.h" |
31 #include "tcp-header.h" |
32 #include "tcp-header.h" |
32 #include "ipv4-end-point-demux.h" |
33 #include "ipv4-end-point-demux.h" |
33 #include "ipv4-end-point.h" |
34 #include "ipv4-end-point.h" |
34 #include "ipv4-l3-protocol.h" |
35 #include "ipv4-l3-protocol.h" |
|
36 #include "tcp-socket-factory-impl.h" |
35 |
37 |
36 #include "tcp-typedefs.h" |
38 #include "tcp-typedefs.h" |
37 |
39 |
38 #include <vector> |
40 #include <vector> |
39 #include <sstream> |
41 #include <sstream> |
322 TypeId |
324 TypeId |
323 TcpL4Protocol::GetTypeId (void) |
325 TcpL4Protocol::GetTypeId (void) |
324 { |
326 { |
325 static TypeId tid = TypeId ("ns3::TcpL4Protocol") |
327 static TypeId tid = TypeId ("ns3::TcpL4Protocol") |
326 .SetParent<Ipv4L4Protocol> () |
328 .SetParent<Ipv4L4Protocol> () |
|
329 .AddConstructor<TcpL4Protocol> () |
327 .AddAttribute ("RttEstimatorFactory", |
330 .AddAttribute ("RttEstimatorFactory", |
328 "How RttEstimator objects are created.", |
331 "How RttEstimator objects are created.", |
329 ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), |
332 ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), |
330 MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), |
333 MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), |
331 MakeObjectFactoryChecker ()) |
334 MakeObjectFactoryChecker ()) |
356 |
359 |
357 void |
360 void |
358 TcpL4Protocol::SetNode (Ptr<Node> node) |
361 TcpL4Protocol::SetNode (Ptr<Node> node) |
359 { |
362 { |
360 m_node = node; |
363 m_node = node; |
|
364 } |
|
365 |
|
366 /* |
|
367 * This method is called by AddAgregate and completes the aggregation |
|
368 * by setting the node in the TCP stack, link it to the ipv4 stack and |
|
369 * adding TCP socket factory to the node. |
|
370 */ |
|
371 void |
|
372 TcpL4Protocol::NotifyNewAggregate () |
|
373 { |
|
374 bool is_not_initialized = (m_node == 0); |
|
375 Ptr<Node>node = this->GetObject<Node> (); |
|
376 Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> (); |
|
377 if (is_not_initialized && node!= 0 && ipv4 != 0) |
|
378 { |
|
379 this->SetNode (node); |
|
380 ipv4->Insert (this); |
|
381 Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> (); |
|
382 tcpFactory->SetTcp (this); |
|
383 node->AggregateObject (tcpFactory); |
|
384 } |
|
385 Object::NotifyNewAggregate (); |
361 } |
386 } |
362 |
387 |
363 int |
388 int |
364 TcpL4Protocol::GetProtocolNumber (void) const |
389 TcpL4Protocol::GetProtocolNumber (void) const |
365 { |
390 { |
518 |
543 |
519 Ptr<Ipv4L3Protocol> ipv4 = |
544 Ptr<Ipv4L3Protocol> ipv4 = |
520 m_node->GetObject<Ipv4L3Protocol> (); |
545 m_node->GetObject<Ipv4L3Protocol> (); |
521 if (ipv4 != 0) |
546 if (ipv4 != 0) |
522 { |
547 { |
523 ipv4->Send (packet, saddr, daddr, PROT_NUMBER); |
548 // XXX We've already performed the route lookup in TcpSocketImpl |
|
549 // should be cached. |
|
550 Ipv4Header header; |
|
551 header.SetDestination (daddr); |
|
552 Socket::SocketErrno errno; |
|
553 Ptr<Ipv4Route> route; |
|
554 uint32_t oif = 0; //specify non-zero if bound to a source address |
|
555 route = ipv4->GetRoutingProtocol ()->RouteOutput (header, oif, errno); |
|
556 ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); |
524 } |
557 } |
525 } |
558 } |
526 |
559 |
527 void |
560 void |
528 TcpL4Protocol::SendPacket (Ptr<Packet> packet, TcpHeader outgoingHeader, |
561 TcpL4Protocol::SendPacket (Ptr<Packet> packet, TcpHeader outgoingHeader, |
548 |
581 |
549 Ptr<Ipv4L3Protocol> ipv4 = |
582 Ptr<Ipv4L3Protocol> ipv4 = |
550 m_node->GetObject<Ipv4L3Protocol> (); |
583 m_node->GetObject<Ipv4L3Protocol> (); |
551 if (ipv4 != 0) |
584 if (ipv4 != 0) |
552 { |
585 { |
553 ipv4->Send (packet, saddr, daddr, PROT_NUMBER); |
586 // XXX We've already performed the route lookup in TcpSocketImpl |
|
587 // should be cached. |
|
588 Ipv4Header header; |
|
589 header.SetDestination (daddr); |
|
590 Socket::SocketErrno errno; |
|
591 Ptr<Ipv4Route> route; |
|
592 uint32_t oif = 0; //specify non-zero if bound to a source address |
|
593 route = ipv4->GetRoutingProtocol ()->RouteOutput (header, oif, errno); |
|
594 ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); |
554 } |
595 } |
555 else |
596 else |
556 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface"); |
597 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface"); |
557 } |
598 } |
558 |
599 |