View | Details | Raw Unified | Return to bug 748
Collapse All | Expand All

(-)a/src/internet-stack/ipv4-end-point.cc (-5 / +5 lines)
 Lines 89-95    Link Here 
89
}
89
}
90
90
91
void 
91
void 
92
Ipv4EndPoint::SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback)
92
Ipv4EndPoint::SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> callback)
93
{
93
{
94
  m_rxCallback = callback;
94
  m_rxCallback = callback;
95
}
95
}
 Lines 106-122    Link Here 
106
}
106
}
107
107
108
void 
108
void 
109
Ipv4EndPoint::ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport)
109
Ipv4EndPoint::ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport)
110
{
110
{
111
  if (!m_rxCallback.IsNull ())
111
  if (!m_rxCallback.IsNull ())
112
    {
112
    {
113
      Simulator::ScheduleNow (&Ipv4EndPoint::DoForwardUp, this, p, saddr, sport);
113
      Simulator::ScheduleNow (&Ipv4EndPoint::DoForwardUp, this, p, saddr, daddr, sport);
114
    }
114
    }
115
}
115
}
116
void 
116
void 
117
Ipv4EndPoint::DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport)
117
Ipv4EndPoint::DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport)
118
{
118
{
119
  m_rxCallback (p, saddr, sport);
119
  m_rxCallback (p, saddr, daddr, sport);
120
}
120
}
121
121
122
void 
122
void 
(-)a/src/internet-stack/ipv4-end-point.h (-4 / +4 lines)
 Lines 59-71    Link Here 
59
  Ptr<NetDevice> GetBoundNetDevice (void);
59
  Ptr<NetDevice> GetBoundNetDevice (void);
60
60
61
  // Called from socket implementations to get notified about important events.
61
  // Called from socket implementations to get notified about important events.
62
  void SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback);
62
  void SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> callback);
63
  void SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback);
63
  void SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback);
64
  void SetDestroyCallback (Callback<void> callback);
64
  void SetDestroyCallback (Callback<void> callback);
65
65
66
  // Called from an L4Protocol implementation to notify an endpoint of a
66
  // Called from an L4Protocol implementation to notify an endpoint of a
67
  // packet reception.
67
  // packet reception.
68
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport);
68
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport);
69
  // Called from an L4Protocol implementation to notify an endpoint of
69
  // Called from an L4Protocol implementation to notify an endpoint of
70
  // an icmp message reception.
70
  // an icmp message reception.
71
  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
71
  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
 Lines 73-79    Link Here 
73
                    uint32_t icmpInfo);
73
                    uint32_t icmpInfo);
74
74
75
private:
75
private:
76
  void DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport);
76
  void DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport);
77
  void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
77
  void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
78
                      uint8_t icmpType, uint8_t icmpCode,
78
                      uint8_t icmpType, uint8_t icmpCode,
79
                      uint32_t icmpInfo);
79
                      uint32_t icmpInfo);
 Lines 82-88    Link Here 
82
  Ipv4Address m_peerAddr;
82
  Ipv4Address m_peerAddr;
83
  uint16_t m_peerPort;
83
  uint16_t m_peerPort;
84
  Ptr<NetDevice> m_boundnetdevice;
84
  Ptr<NetDevice> m_boundnetdevice;
85
  Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> m_rxCallback;
85
  Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> m_rxCallback;
86
  Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
86
  Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
87
  Callback<void> m_destroyCallback;
87
  Callback<void> m_destroyCallback;
88
};
88
};
(-)a/src/internet-stack/nsc-tcp-l4-protocol.cc (-1 / +1 lines)
 Lines 382-388    Link Here 
382
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
382
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
383
       endPoint != endPoints.end (); endPoint++) {
383
       endPoint != endPoints.end (); endPoint++) {
384
          // NSC HACK: (ab)use TcpSocket::ForwardUp for signalling
384
          // NSC HACK: (ab)use TcpSocket::ForwardUp for signalling
385
          (*endPoint)->ForwardUp (NULL, Ipv4Address(), 0);
385
          (*endPoint)->ForwardUp (NULL, Ipv4Address(), Ipv4Address(), 0);
386
  }
386
  }
387
}
387
}
388
388
(-)a/src/internet-stack/nsc-tcp-socket-impl.cc (-1 / +1 lines)
 Lines 465-471    Link Here 
465
}
465
}
466
466
467
void
467
void
468
NscTcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
468
NscTcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
469
{
469
{
470
  NSCWakeup();
470
  NSCWakeup();
471
}
471
}
(-)a/src/internet-stack/nsc-tcp-socket-impl.h (-1 / +1 lines)
 Lines 88-94    Link Here 
88
  friend class Tcp;
88
  friend class Tcp;
89
  // invoked by Tcp class
89
  // invoked by Tcp class
90
  int FinishBind (void);
90
  int FinishBind (void);
91
  void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
91
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
92
  void Destroy (void);
92
  void Destroy (void);
93
  //methods for state
93
  //methods for state
94
  bool SendPendingData(void);
94
  bool SendPendingData(void);
(-)a/src/internet-stack/tcp-l4-protocol.cc (-1 / +1 lines)
 Lines 546-552    Link Here 
546
  }
546
  }
547
  NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
547
  NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
548
  NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
548
  NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
549
  (*endPoints.begin ())->ForwardUp (packet, source, tcpHeader.GetSourcePort ());
549
  (*endPoints.begin ())->ForwardUp (packet, source, destination, tcpHeader.GetSourcePort ());
550
  return Ipv4L4Protocol::RX_OK;
550
  return Ipv4L4Protocol::RX_OK;
551
}
551
}
552
552
(-)a/src/internet-stack/tcp-socket-impl.cc (-74 / +48 lines)
 Lines 70-77    Link Here 
70
    m_endPoint (0),
70
    m_endPoint (0),
71
    m_node (0),
71
    m_node (0),
72
    m_tcp (0),
72
    m_tcp (0),
73
    m_localAddress (Ipv4Address::GetZero ()),
74
    m_localPort (0),
75
    m_errno (ERROR_NOTERROR),
73
    m_errno (ERROR_NOTERROR),
76
    m_shutdownSend (false),
74
    m_shutdownSend (false),
77
    m_shutdownRecv (false),
75
    m_shutdownRecv (false),
 Lines 109-118    Link Here 
109
    m_endPoint (0),
107
    m_endPoint (0),
110
    m_node (sock.m_node),
108
    m_node (sock.m_node),
111
    m_tcp (sock.m_tcp),
109
    m_tcp (sock.m_tcp),
112
    m_remoteAddress (sock.m_remoteAddress),
113
    m_remotePort (sock.m_remotePort),
114
    m_localAddress (sock.m_localAddress),
115
    m_localPort (sock.m_localPort),
116
    m_errno (sock.m_errno),
110
    m_errno (sock.m_errno),
117
    m_shutdownSend (sock.m_shutdownSend),
111
    m_shutdownSend (sock.m_shutdownSend),
118
    m_shutdownRecv (sock.m_shutdownRecv),
112
    m_shutdownRecv (sock.m_shutdownRecv),
 Lines 266-273    Link Here 
266
    }
260
    }
267
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
261
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
268
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
262
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
269
  m_localAddress = m_endPoint->GetLocalAddress ();
270
  m_localPort = m_endPoint->GetLocalPort ();
271
  return 0;
263
  return 0;
272
}
264
}
273
265
 Lines 377-389    Link Here 
377
      NS_ASSERT (m_endPoint != 0);
369
      NS_ASSERT (m_endPoint != 0);
378
    }
370
    }
379
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
371
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
380
  m_remoteAddress = transport.GetIpv4 ();
372
  m_endPoint->SetPeer(transport.GetIpv4 (), transport.GetPort ());
381
  m_remotePort = transport.GetPort ();
382
  
373
  
383
  if (ipv4->GetRoutingProtocol () != 0)
374
  if (ipv4->GetRoutingProtocol () != 0)
384
    {
375
    {
385
      Ipv4Header header;
376
      Ipv4Header header;
386
      header.SetDestination (m_remoteAddress);
377
      header.SetDestination (m_endPoint->GetPeerAddress());
387
      Socket::SocketErrno errno_;
378
      Socket::SocketErrno errno_;
388
      Ptr<Ipv4Route> route;
379
      Ptr<Ipv4Route> route;
389
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
380
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
 Lines 396-402    Link Here 
396
        }
387
        }
397
      else
388
      else
398
        {
389
        {
399
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_remoteAddress << " does not exist");
390
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_endPoint->GetPeerAddress() << " does not exist");
400
          NS_LOG_ERROR (errno_);
391
          NS_LOG_ERROR (errno_);
401
          m_errno = errno_;
392
          m_errno = errno_;
402
          return -1;
393
          return -1;
 Lines 602-608    Link Here 
602
    }
593
    }
603
  }
594
  }
604
  SocketAddressTag tag;
595
  SocketAddressTag tag;
605
  tag.SetAddress (InetSocketAddress (m_remoteAddress, m_remotePort));
596
  tag.SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort()));
606
  outPacket->AddPacketTag (tag);
597
  outPacket->AddPacketTag (tag);
607
  return outPacket;
598
  return outPacket;
608
}
599
}
 Lines 638-644    Link Here 
638
TcpSocketImpl::GetSockName (Address &address) const
629
TcpSocketImpl::GetSockName (Address &address) const
639
{
630
{
640
  NS_LOG_FUNCTION_NOARGS ();
631
  NS_LOG_FUNCTION_NOARGS ();
641
  address = InetSocketAddress(m_localAddress, m_localPort);
632
  address = InetSocketAddress(m_endPoint->GetLocalAddress (), 
633
                              m_endPoint->GetLocalPort ());
642
  return 0;
634
  return 0;
643
}
635
}
644
636
 Lines 661-667    Link Here 
661
}
653
}
662
654
663
void
655
void
664
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
656
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
665
{
657
{
666
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
658
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
667
               " dport " << m_endPoint->GetLocalPort() <<
659
               " dport " << m_endPoint->GetLocalPort() <<
 Lines 669-675    Link Here 
669
               " sport " << m_endPoint->GetPeerPort() <<
661
               " sport " << m_endPoint->GetPeerPort() <<
670
               " saddr " << m_endPoint->GetPeerAddress());
662
               " saddr " << m_endPoint->GetPeerAddress());
671
663
672
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
664
  NS_LOG_FUNCTION (this << packet << saddr << daddr << port);
665
666
  Address fromAddress = InetSocketAddress (saddr, port);
667
  Address toAddress = InetSocketAddress (daddr, m_endPoint->GetLocalPort());
668
673
  if (m_shutdownRecv)
669
  if (m_shutdownRecv)
674
    {
670
    {
675
      return;
671
      return;
 Lines 695-705    Link Here 
695
691
696
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
692
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
697
  Actions_t action = ProcessEvent (event); //updates the state
693
  Actions_t action = ProcessEvent (event); //updates the state
698
  Address address = InetSocketAddress (ipv4, port);
699
  NS_LOG_DEBUG("Socket " << this << 
694
  NS_LOG_DEBUG("Socket " << this << 
700
               " processing pkt action, " << action <<
695
               " processing pkt action, " << action <<
701
               " current state " << m_state);
696
               " current state " << m_state);
702
  ProcessPacketAction (action, packet, tcpHeader, address);
697
  ProcessPacketAction (action, packet, tcpHeader, fromAddress, toAddress);
703
}
698
}
704
699
705
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
700
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
 Lines 727-733    Link Here 
727
    {
722
    {
728
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
723
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
729
      m_connected = true;
724
      m_connected = true;
730
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
731
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
725
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
732
    }
726
    }
733
  if (saveState < CLOSING && (m_state == CLOSING || m_state == TIMED_WAIT) )
727
  if (saveState < CLOSING && (m_state == CLOSING || m_state == TIMED_WAIT) )
 Lines 787-796    Link Here 
787
  header.SetSequenceNumber (m_nextTxSequence);
781
  header.SetSequenceNumber (m_nextTxSequence);
788
  header.SetAckNumber (m_nextRxSequence);
782
  header.SetAckNumber (m_nextRxSequence);
789
  header.SetSourcePort (m_endPoint->GetLocalPort ());
783
  header.SetSourcePort (m_endPoint->GetLocalPort ());
790
  header.SetDestinationPort (m_remotePort);
784
  header.SetDestinationPort (m_endPoint->GetPeerPort ());
791
  header.SetWindowSize (AdvertisedWindowSize());
785
  header.SetWindowSize (AdvertisedWindowSize());
792
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
786
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
793
    m_remoteAddress, m_boundnetdevice);
787
    m_endPoint->GetPeerAddress (), m_boundnetdevice);
794
  Time rto = m_rtt->RetransmitTimeout ();
788
  Time rto = m_rtt->RetransmitTimeout ();
795
  bool hasSyn = flags & TcpHeader::SYN;
789
  bool hasSyn = flags & TcpHeader::SYN;
796
  bool hasFin = flags & TcpHeader::FIN;
790
  bool hasFin = flags & TcpHeader::FIN;
 Lines 901-907    Link Here 
901
895
902
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
896
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
903
                                     const TcpHeader& tcpHeader,
897
                                     const TcpHeader& tcpHeader,
904
                                     const Address& fromAddress)
898
                                     const Address& fromAddress,
899
                                     const Address& toAddress)
905
{
900
{
906
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
901
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
907
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
902
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
 Lines 935-974    Link Here 
935
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
930
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
936
          //this listening socket should do nothing more
931
          //this listening socket should do nothing more
937
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
932
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
938
                                  p, tcpHeader,fromAddress);
933
                                  p, tcpHeader, fromAddress, toAddress);
939
          return true;
934
          return true;
940
        }
935
        }
941
        // This is the cloned endpoint
936
      else
942
        m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
937
        {
938
          // This is the cloned endpoint
939
          // TCP SYN consumes one byte
940
          m_nextRxSequence = tcpHeader.GetSequenceNumber () 
941
                             + SequenceNumber (1);
942
          SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
943
        }
943
944
944
        // Look up the source address
945
        if (ipv4->GetRoutingProtocol () != 0)
946
          {
947
            Ipv4Header header;
948
            Socket::SocketErrno errno_;
949
            Ptr<Ipv4Route> route;
950
            Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
951
            header.SetDestination (m_remoteAddress);
952
            route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
953
            if (route != 0)
954
              {
955
                NS_LOG_LOGIC ("Route exists");
956
                m_endPoint->SetLocalAddress (route->GetSource ());
957
              }
958
            else
959
              {
960
                NS_LOG_ERROR (errno_);
961
                m_errno = errno_;
962
                return -1;
963
              }
964
          }
965
        else
966
          {
967
            NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
968
          }
969
        // TCP SYN consumes one byte
970
        m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
971
        SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
972
      break;
945
      break;
973
    case ACK_TX_1:
946
    case ACK_TX_1:
974
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
947
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
 Lines 1001-1007    Link Here 
1001
                                 NEW_SEQ_RX,
974
                                 NEW_SEQ_RX,
1002
                                 p,
975
                                 p,
1003
                                 tcpHeader,
976
                                 tcpHeader,
1004
                                 fromAddress);
977
                                 fromAddress,
978
                                 toAddress);
1005
        }
979
        }
1006
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
980
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
1007
      {
981
      {
 Lines 1025-1031    Link Here 
1025
      break;
999
      break;
1026
    case NEW_SEQ_RX:
1000
    case NEW_SEQ_RX:
1027
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
1001
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
1028
      NewRx (p, tcpHeader, fromAddress); // Process new data received
1002
      NewRx (p, tcpHeader, fromAddress, toAddress); // Process new data received
1029
      break;
1003
      break;
1030
    case PEER_CLOSE:
1004
    case PEER_CLOSE:
1031
    {
1005
    {
 Lines 1039-1052    Link Here 
1039
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
1013
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
1040
            << " rxseq " << tcpHeader.GetSequenceNumber () 
1014
            << " rxseq " << tcpHeader.GetSequenceNumber () 
1041
            << " nextRxSeq " << m_nextRxSequence);
1015
            << " nextRxSeq " << m_nextRxSequence);
1042
          NewRx (p, tcpHeader, fromAddress);
1016
          NewRx (p, tcpHeader, fromAddress, toAddress);
1043
          return true;
1017
          return true;
1044
        }
1018
        }
1045
      // Now we need to see if any data came with the FIN
1019
      // Now we need to see if any data came with the FIN
1046
      // if so, call NewRx
1020
      // if so, call NewRx
1047
      if (p->GetSize () != 0)
1021
      if (p->GetSize () != 0)
1048
        {
1022
        {
1049
          NewRx (p, tcpHeader, fromAddress);
1023
          NewRx (p, tcpHeader, fromAddress, toAddress);
1050
        }
1024
        }
1051
      ++m_nextRxSequence; //bump this to account for the FIN
1025
      ++m_nextRxSequence; //bump this to account for the FIN
1052
      States_t saveState = m_state; // Used to see if app responds
1026
      States_t saveState = m_state; // Used to see if app responds
 Lines 1078-1084    Link Here 
1078
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
1052
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
1079
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
1053
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
1080
      m_connected = true; // ! This is bogus; fix when we clone the tcp
1054
      m_connected = true; // ! This is bogus; fix when we clone the tcp
1081
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
1055
      m_endPoint->SetPeer (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort());
1082
      //treat the connection orientation final ack as a newack
1056
      //treat the connection orientation final ack as a newack
1083
      CommonNewAck (tcpHeader.GetAckNumber (), true);
1057
      CommonNewAck (tcpHeader.GetAckNumber (), true);
1084
      NotifyNewConnectionCreated (this, fromAddress);
1058
      NotifyNewConnectionCreated (this, fromAddress);
 Lines 1089-1109    Link Here 
1089
  return true;
1063
  return true;
1090
}
1064
}
1091
1065
1092
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress)
1066
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress, const Address& toAddress)
1093
{
1067
{
1094
  // Get port and address from peer (connecting host)
1068
  // Get port and address from peer (connecting host)
1095
  m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
1069
  m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom(toAddress).GetIpv4 (),
1096
  m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
1070
                                InetSocketAddress::ConvertFrom(toAddress).GetPort (),
1097
  m_endPoint = m_tcp->Allocate (m_localAddress,
1071
                                InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
1098
                                m_localPort,
1072
                                InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
1099
                                m_remoteAddress,
1100
                                m_remotePort);
1101
  //the cloned socket with be in listen state, so manually change state
1073
  //the cloned socket with be in listen state, so manually change state
1102
  m_state = SYN_RCVD;
1074
  m_state = SYN_RCVD;
1103
  //equivalent to FinishBind
1075
  //equivalent to FinishBind
1104
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
1076
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
1105
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
1077
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
1106
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress);
1078
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress, toAddress);
1107
 }
1079
 }
1108
1080
1109
void TcpSocketImpl::ConnectionSucceeded()
1081
void TcpSocketImpl::ConnectionSucceeded()
 Lines 1165-1171    Link Here 
1165
      header.SetSequenceNumber (m_nextTxSequence);
1137
      header.SetSequenceNumber (m_nextTxSequence);
1166
      header.SetAckNumber (m_nextRxSequence);
1138
      header.SetAckNumber (m_nextRxSequence);
1167
      header.SetSourcePort (m_endPoint->GetLocalPort());
1139
      header.SetSourcePort (m_endPoint->GetLocalPort());
1168
      header.SetDestinationPort (m_remotePort);
1140
      header.SetDestinationPort (m_endPoint->GetPeerPort());
1169
      header.SetWindowSize (AdvertisedWindowSize());
1141
      header.SetWindowSize (AdvertisedWindowSize());
1170
      if (m_shutdownSend)
1142
      if (m_shutdownSend)
1171
        {
1143
        {
 Lines 1185-1191    Link Here 
1185
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
1157
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
1186
      m_tcp->SendPacket (p, header,
1158
      m_tcp->SendPacket (p, header,
1187
                         m_endPoint->GetLocalAddress (),
1159
                         m_endPoint->GetLocalAddress (),
1188
                         m_remoteAddress, m_boundnetdevice);
1160
                         m_endPoint->GetPeerAddress (), 
1161
                         m_boundnetdevice);
1189
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
1162
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
1190
      // Notify the application of the data being sent
1163
      // Notify the application of the data being sent
1191
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz);
1164
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz);
 Lines 1243-1249    Link Here 
1243
1216
1244
void TcpSocketImpl::NewRx (Ptr<Packet> p,
1217
void TcpSocketImpl::NewRx (Ptr<Packet> p,
1245
                        const TcpHeader& tcpHeader, 
1218
                        const TcpHeader& tcpHeader, 
1246
                        const Address& fromAddress)
1219
                        const Address& fromAddress,
1220
                        const Address& toAddress)
1247
{
1221
{
1248
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
1222
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
1249
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
1223
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
 Lines 1310-1316    Link Here 
1310
        { // See if we can close now
1284
        { // See if we can close now
1311
          if (m_bufferedData.empty())
1285
          if (m_bufferedData.empty())
1312
            {
1286
            {
1313
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress);
1287
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress, toAddress);
1314
            }
1288
            }
1315
        }
1289
        }
1316
    }
1290
    }
 Lines 1627-1637    Link Here 
1627
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1601
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1628
  tcpHeader.SetAckNumber (m_nextRxSequence);
1602
  tcpHeader.SetAckNumber (m_nextRxSequence);
1629
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1603
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1630
  tcpHeader.SetDestinationPort (m_remotePort);
1604
  tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ());
1631
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1605
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1632
1606
1633
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1607
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1634
    m_remoteAddress, m_boundnetdevice);
1608
    m_endPoint->GetPeerAddress (), m_boundnetdevice);
1635
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
1609
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
1636
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
1610
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
1637
                    << (Simulator::Now () + m_persistTime).GetSeconds());
1611
                    << (Simulator::Now () + m_persistTime).GetSeconds());
 Lines 1692-1703    Link Here 
1692
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1666
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1693
  tcpHeader.SetAckNumber (m_nextRxSequence);
1667
  tcpHeader.SetAckNumber (m_nextRxSequence);
1694
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1668
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1695
  tcpHeader.SetDestinationPort (m_remotePort);
1669
  tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ());
1696
  tcpHeader.SetFlags (flags);
1670
  tcpHeader.SetFlags (flags);
1697
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1671
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1698
1672
1699
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1673
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1700
    m_remoteAddress, m_boundnetdevice);
1674
    m_endPoint->GetPeerAddress (), m_boundnetdevice);
1701
}
1675
}
1702
1676
1703
void
1677
void
(-)a/src/internet-stack/tcp-socket-impl.h (-9 / +6 lines)
 Lines 101-107    Link Here 
101
  friend class Tcp;
101
  friend class Tcp;
102
  // invoked by Tcp class
102
  // invoked by Tcp class
103
  int FinishBind (void);
103
  int FinishBind (void);
104
  void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
104
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
105
  void Destroy (void);
105
  void Destroy (void);
106
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
106
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
107
  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
107
  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
 Lines 114-123    Link Here 
114
                      Ipv4Address saddr, Ipv4Address daddr);
114
                      Ipv4Address saddr, Ipv4Address daddr);
115
  bool ProcessPacketAction (Actions_t a, Ptr<Packet> p,
115
  bool ProcessPacketAction (Actions_t a, Ptr<Packet> p,
116
                                       const TcpHeader& tcpHeader,
116
                                       const TcpHeader& tcpHeader,
117
                                       const Address& fromAddress);
117
                                       const Address& fromAddress,
118
                                       const Address& toAddress);
118
  Actions_t ProcessEvent (Events_t e);
119
  Actions_t ProcessEvent (Events_t e);
119
  bool SendPendingData(bool withAck = false);
120
  bool SendPendingData(bool withAck = false);
120
  void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress);
121
  void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
121
  void ConnectionSucceeded();
122
  void ConnectionSucceeded();
122
  
123
  
123
  //methods for window management
124
  //methods for window management
 Lines 131-137    Link Here 
131
  uint16_t AdvertisedWindowSize();
132
  uint16_t AdvertisedWindowSize();
132
133
133
  // Manage data tx/rx
134
  // Manage data tx/rx
134
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address&);
135
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
135
  void RxBufFinishInsert (SequenceNumber);
136
  void RxBufFinishInsert (SequenceNumber);
136
  Ptr<TcpSocketImpl> Copy ();
137
  Ptr<TcpSocketImpl> Copy ();
137
  virtual void NewAck (SequenceNumber seq); 
138
  virtual void NewAck (SequenceNumber seq); 
 Lines 178-188    Link Here 
178
  Ipv4EndPoint *m_endPoint;
179
  Ipv4EndPoint *m_endPoint;
179
  Ptr<Node> m_node;
180
  Ptr<Node> m_node;
180
  Ptr<TcpL4Protocol> m_tcp;
181
  Ptr<TcpL4Protocol> m_tcp;
181
  Ipv4Address m_remoteAddress;
182
182
  uint16_t m_remotePort;
183
  //these two are so that the socket/endpoint cloning works
184
  Ipv4Address m_localAddress;
185
  uint16_t m_localPort;
186
  enum SocketErrno m_errno;
183
  enum SocketErrno m_errno;
187
  bool m_shutdownSend;
184
  bool m_shutdownSend;
188
  bool m_shutdownRecv;
185
  bool m_shutdownRecv;
(-)a/src/internet-stack/udp-l4-protocol.cc (-1 / +1 lines)
 Lines 230-236    Link Here 
230
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
230
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
231
       endPoint != endPoints.end (); endPoint++)
231
       endPoint != endPoints.end (); endPoint++)
232
    {
232
    {
233
      (*endPoint)->ForwardUp (packet->Copy (), source, udpHeader.GetSourcePort ());
233
      (*endPoint)->ForwardUp (packet->Copy (), source, destination, udpHeader.GetSourcePort ());
234
    }
234
    }
235
  return Ipv4L4Protocol::RX_OK;
235
  return Ipv4L4Protocol::RX_OK;
236
}
236
}
(-)a/src/internet-stack/udp-socket-impl.cc (-3 / +3 lines)
 Lines 583-591    Link Here 
583
}
583
}
584
584
585
void 
585
void 
586
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
586
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
587
{
587
{
588
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
588
  NS_LOG_FUNCTION (this << packet << saddr << daddr << port);
589
589
590
  if (m_shutdownRecv)
590
  if (m_shutdownRecv)
591
    {
591
    {
 Lines 593-599    Link Here 
593
    }
593
    }
594
  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
594
  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
595
    {
595
    {
596
      Address address = InetSocketAddress (ipv4, port);
596
      Address address = InetSocketAddress (saddr, port);
597
      SocketAddressTag tag;
597
      SocketAddressTag tag;
598
      tag.SetAddress (address);
598
      tag.SetAddress (address);
599
      packet->AddPacketTag (tag);
599
      packet->AddPacketTag (tag);
(-)a/src/internet-stack/udp-socket-impl.h (-1 / +1 lines)
 Lines 98-104    Link Here 
98
  friend class UdpSocketFactory;
98
  friend class UdpSocketFactory;
99
  // invoked by Udp class
99
  // invoked by Udp class
100
  int FinishBind (void);
100
  int FinishBind (void);
101
  void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
101
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
102
  void Destroy (void);
102
  void Destroy (void);
103
  int DoSend (Ptr<Packet> p);
103
  int DoSend (Ptr<Packet> p);
104
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
104
  int DoSendTo (Ptr<Packet> p, const Address &daddr);

Return to bug 748