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

(-)a/src/internet-stack/ipv4-end-point.cc (-5 / +5 lines)
 Lines 76-82    Link Here 
76
}
76
}
77
77
78
void 
78
void 
79
Ipv4EndPoint::SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback)
79
Ipv4EndPoint::SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> callback)
80
{
80
{
81
  m_rxCallback = callback;
81
  m_rxCallback = callback;
82
}
82
}
 Lines 93-109    Link Here 
93
}
93
}
94
94
95
void 
95
void 
96
Ipv4EndPoint::ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport)
96
Ipv4EndPoint::ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport)
97
{
97
{
98
  if (!m_rxCallback.IsNull ())
98
  if (!m_rxCallback.IsNull ())
99
    {
99
    {
100
      Simulator::ScheduleNow (&Ipv4EndPoint::DoForwardUp, this, p, saddr, sport);
100
      Simulator::ScheduleNow (&Ipv4EndPoint::DoForwardUp, this, p, saddr, daddr, sport);
101
    }
101
    }
102
}
102
}
103
void 
103
void 
104
Ipv4EndPoint::DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport)
104
Ipv4EndPoint::DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport)
105
{
105
{
106
  m_rxCallback (p, saddr, sport);
106
  m_rxCallback (p, saddr, daddr, sport);
107
}
107
}
108
108
109
void 
109
void 
(-)a/src/internet-stack/ipv4-end-point.h (-4 / +4 lines)
 Lines 55-67    Link Here 
55
  void SetPeer (Ipv4Address address, uint16_t port);
55
  void SetPeer (Ipv4Address address, uint16_t port);
56
56
57
  // Called from socket implementations to get notified about important events.
57
  // Called from socket implementations to get notified about important events.
58
  void SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback);
58
  void SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> callback);
59
  void SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback);
59
  void SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback);
60
  void SetDestroyCallback (Callback<void> callback);
60
  void SetDestroyCallback (Callback<void> callback);
61
61
62
  // Called from an L4Protocol implementation to notify an endpoint of a
62
  // Called from an L4Protocol implementation to notify an endpoint of a
63
  // packet reception.
63
  // packet reception.
64
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport);
64
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport);
65
  // Called from an L4Protocol implementation to notify an endpoint of
65
  // Called from an L4Protocol implementation to notify an endpoint of
66
  // an icmp message reception.
66
  // an icmp message reception.
67
  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
67
  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
 Lines 69-75    Link Here 
69
                    uint32_t icmpInfo);
69
                    uint32_t icmpInfo);
70
70
71
private:
71
private:
72
  void DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport);
72
  void DoForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport);
73
  void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
73
  void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, 
74
                      uint8_t icmpType, uint8_t icmpCode,
74
                      uint8_t icmpType, uint8_t icmpCode,
75
                      uint32_t icmpInfo);
75
                      uint32_t icmpInfo);
 Lines 77-83    Link Here 
77
  uint16_t m_localPort;
77
  uint16_t m_localPort;
78
  Ipv4Address m_peerAddr;
78
  Ipv4Address m_peerAddr;
79
  uint16_t m_peerPort;
79
  uint16_t m_peerPort;
80
  Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> m_rxCallback;
80
  Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint16_t> m_rxCallback;
81
  Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
81
  Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
82
  Callback<void> m_destroyCallback;
82
  Callback<void> m_destroyCallback;
83
};
83
};
(-)a/src/internet-stack/tcp-l4-protocol.cc (-1 / +1 lines)
 Lines 542-548    Link Here 
542
  }
542
  }
543
  NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
543
  NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
544
  NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
544
  NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
545
  (*endPoints.begin ())->ForwardUp (packet, source, tcpHeader.GetSourcePort ());
545
  (*endPoints.begin ())->ForwardUp (packet, source, destination, tcpHeader.GetSourcePort ());
546
  return Ipv4L4Protocol::RX_OK;
546
  return Ipv4L4Protocol::RX_OK;
547
}
547
}
548
548
(-)a/src/internet-stack/tcp-socket-impl.cc (-74 / +44 lines)
 Lines 68-75    Link Here 
68
    m_endPoint (0),
68
    m_endPoint (0),
69
    m_node (0),
69
    m_node (0),
70
    m_tcp (0),
70
    m_tcp (0),
71
    m_localAddress (Ipv4Address::GetZero ()),
72
    m_localPort (0),
73
    m_errno (ERROR_NOTERROR),
71
    m_errno (ERROR_NOTERROR),
74
    m_shutdownSend (false),
72
    m_shutdownSend (false),
75
    m_shutdownRecv (false),
73
    m_shutdownRecv (false),
 Lines 107-116    Link Here 
107
    m_endPoint (0),
105
    m_endPoint (0),
108
    m_node (sock.m_node),
106
    m_node (sock.m_node),
109
    m_tcp (sock.m_tcp),
107
    m_tcp (sock.m_tcp),
110
    m_remoteAddress (sock.m_remoteAddress),
111
    m_remotePort (sock.m_remotePort),
112
    m_localAddress (sock.m_localAddress),
113
    m_localPort (sock.m_localPort),
114
    m_errno (sock.m_errno),
108
    m_errno (sock.m_errno),
115
    m_shutdownSend (sock.m_shutdownSend),
109
    m_shutdownSend (sock.m_shutdownSend),
116
    m_shutdownRecv (sock.m_shutdownRecv),
110
    m_shutdownRecv (sock.m_shutdownRecv),
 Lines 264-271    Link Here 
264
    }
258
    }
265
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
259
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
266
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
260
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
267
  m_localAddress = m_endPoint->GetLocalAddress ();
268
  m_localPort = m_endPoint->GetLocalPort ();
269
  return 0;
261
  return 0;
270
}
262
}
271
263
 Lines 375-387    Link Here 
375
      NS_ASSERT (m_endPoint != 0);
367
      NS_ASSERT (m_endPoint != 0);
376
    }
368
    }
377
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
369
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
378
  m_remoteAddress = transport.GetIpv4 ();
370
  m_endPoint->SetPeer(transport.GetIpv4 (), transport.GetPort ());
379
  m_remotePort = transport.GetPort ();
380
  
371
  
381
  if (ipv4->GetRoutingProtocol () != 0)
372
  if (ipv4->GetRoutingProtocol () != 0)
382
    {
373
    {
383
      Ipv4Header header;
374
      Ipv4Header header;
384
      header.SetDestination (m_remoteAddress);
375
      header.SetDestination (m_endPoint->GetPeerAddress());
385
      Socket::SocketErrno errno_;
376
      Socket::SocketErrno errno_;
386
      Ptr<Ipv4Route> route;
377
      Ptr<Ipv4Route> route;
387
      uint32_t oif = 0; //specify non-zero if bound to a source address
378
      uint32_t oif = 0; //specify non-zero if bound to a source address
 Lines 394-400    Link Here 
394
        }
385
        }
395
      else
386
      else
396
        {
387
        {
397
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_remoteAddress << " does not exist");
388
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_endPoint->GetPeerAddress() << " does not exist");
398
          NS_LOG_ERROR (errno_);
389
          NS_LOG_ERROR (errno_);
399
          m_errno = errno_;
390
          m_errno = errno_;
400
          return -1;
391
          return -1;
 Lines 600-606    Link Here 
600
    }
591
    }
601
  }
592
  }
602
  SocketAddressTag tag;
593
  SocketAddressTag tag;
603
  tag.SetAddress (InetSocketAddress (m_remoteAddress, m_remotePort));
594
  tag.SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort()));
604
  outPacket->AddPacketTag (tag);
595
  outPacket->AddPacketTag (tag);
605
  return outPacket;
596
  return outPacket;
606
}
597
}
 Lines 636-647    Link Here 
636
TcpSocketImpl::GetSockName (Address &address) const
627
TcpSocketImpl::GetSockName (Address &address) const
637
{
628
{
638
  NS_LOG_FUNCTION_NOARGS ();
629
  NS_LOG_FUNCTION_NOARGS ();
639
  address = InetSocketAddress(m_localAddress, m_localPort);
630
  address = InetSocketAddress(m_endPoint->GetLocalAddress(), m_endPoint->GetLocalPort());
640
  return 0;
631
  return 0;
641
}
632
}
642
633
643
void
634
void
644
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
635
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
645
{
636
{
646
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
637
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
647
               " dport " << m_endPoint->GetLocalPort() <<
638
               " dport " << m_endPoint->GetLocalPort() <<
 Lines 649-655    Link Here 
649
               " sport " << m_endPoint->GetPeerPort() <<
640
               " sport " << m_endPoint->GetPeerPort() <<
650
               " saddr " << m_endPoint->GetPeerAddress());
641
               " saddr " << m_endPoint->GetPeerAddress());
651
642
652
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
643
  NS_LOG_FUNCTION (this << packet << saddr << daddr << port);
644
645
  Address fromAddress = InetSocketAddress (saddr, port);
646
  Address toAddress = InetSocketAddress (daddr, m_endPoint->GetLocalPort());
647
653
  if (m_shutdownRecv)
648
  if (m_shutdownRecv)
654
    {
649
    {
655
      return;
650
      return;
 Lines 675-685    Link Here 
675
670
676
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
671
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
677
  Actions_t action = ProcessEvent (event); //updates the state
672
  Actions_t action = ProcessEvent (event); //updates the state
678
  Address address = InetSocketAddress (ipv4, port);
679
  NS_LOG_DEBUG("Socket " << this << 
673
  NS_LOG_DEBUG("Socket " << this << 
680
               " processing pkt action, " << action <<
674
               " processing pkt action, " << action <<
681
               " current state " << m_state);
675
               " current state " << m_state);
682
  ProcessPacketAction (action, packet, tcpHeader, address);
676
  ProcessPacketAction (action, packet, tcpHeader, fromAddress, toAddress);
683
}
677
}
684
678
685
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
679
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
 Lines 708-714    Link Here 
708
    {
702
    {
709
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
703
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
710
      m_connected = true;
704
      m_connected = true;
711
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
712
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
705
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
713
    }
706
    }
714
  if (saveState < CLOSING && (m_state == CLOSING || m_state == TIMED_WAIT) )
707
  if (saveState < CLOSING && (m_state == CLOSING || m_state == TIMED_WAIT) )
 Lines 768-777    Link Here 
768
  header.SetSequenceNumber (m_nextTxSequence);
761
  header.SetSequenceNumber (m_nextTxSequence);
769
  header.SetAckNumber (m_nextRxSequence);
762
  header.SetAckNumber (m_nextRxSequence);
770
  header.SetSourcePort (m_endPoint->GetLocalPort ());
763
  header.SetSourcePort (m_endPoint->GetLocalPort ());
771
  header.SetDestinationPort (m_remotePort);
764
  header.SetDestinationPort (m_endPoint->GetPeerPort());
772
  header.SetWindowSize (AdvertisedWindowSize());
765
  header.SetWindowSize (AdvertisedWindowSize());
773
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
766
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
774
    m_remoteAddress);
767
    m_endPoint->GetPeerAddress());
775
  Time rto = m_rtt->RetransmitTimeout ();
768
  Time rto = m_rtt->RetransmitTimeout ();
776
  bool hasSyn = flags & TcpHeader::SYN;
769
  bool hasSyn = flags & TcpHeader::SYN;
777
  bool hasFin = flags & TcpHeader::FIN;
770
  bool hasFin = flags & TcpHeader::FIN;
 Lines 882-888    Link Here 
882
875
883
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
876
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
884
                                     const TcpHeader& tcpHeader,
877
                                     const TcpHeader& tcpHeader,
885
                                     const Address& fromAddress)
878
                                     const Address& fromAddress,
879
                                     const Address& toAddress)
886
{
880
{
887
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
881
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
888
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
882
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
 Lines 916-955    Link Here 
916
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
910
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
917
          //this listening socket should do nothing more
911
          //this listening socket should do nothing more
918
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
912
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
919
                                  p, tcpHeader,fromAddress);
913
                                  p, tcpHeader,fromAddress, toAddress);
920
          return true;
914
          return true;
921
        }
915
        }
922
        // This is the cloned endpoint
916
      else
923
        m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
917
        {// This is the cloned endpoint
918
          // TCP SYN consumes one byte
919
          m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
920
          SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
921
        }
924
922
925
        // Look up the source address
926
        if (ipv4->GetRoutingProtocol () != 0)
927
          {
928
            Ipv4Header header;
929
            Socket::SocketErrno errno_;
930
            Ptr<Ipv4Route> route;
931
            uint32_t oif = 0; //specify non-zero if bound to a source address
932
            header.SetDestination (m_remoteAddress);
933
            route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
934
            if (route != 0)
935
              {
936
                NS_LOG_LOGIC ("Route exists");
937
                m_endPoint->SetLocalAddress (route->GetSource ());
938
              }
939
            else
940
              {
941
                NS_LOG_ERROR (errno_);
942
                m_errno = errno_;
943
                return -1;
944
              }
945
          }
946
        else
947
          {
948
            NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
949
          }
950
        // TCP SYN consumes one byte
951
        m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
952
        SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
953
      break;
923
      break;
954
    case ACK_TX_1:
924
    case ACK_TX_1:
955
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
925
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
 Lines 982-988    Link Here 
982
                                 NEW_SEQ_RX,
952
                                 NEW_SEQ_RX,
983
                                 p,
953
                                 p,
984
                                 tcpHeader,
954
                                 tcpHeader,
985
                                 fromAddress);
955
                                 fromAddress,
956
                                 toAddress);
986
        }
957
        }
987
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
958
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
988
      {
959
      {
 Lines 1006-1012    Link Here 
1006
      break;
977
      break;
1007
    case NEW_SEQ_RX:
978
    case NEW_SEQ_RX:
1008
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
979
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
1009
      NewRx (p, tcpHeader, fromAddress); // Process new data received
980
      NewRx (p, tcpHeader, fromAddress, toAddress); // Process new data received
1010
      break;
981
      break;
1011
    case PEER_CLOSE:
982
    case PEER_CLOSE:
1012
    {
983
    {
 Lines 1020-1033    Link Here 
1020
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
991
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
1021
            << " rxseq " << tcpHeader.GetSequenceNumber () 
992
            << " rxseq " << tcpHeader.GetSequenceNumber () 
1022
            << " nextRxSeq " << m_nextRxSequence);
993
            << " nextRxSeq " << m_nextRxSequence);
1023
          NewRx (p, tcpHeader, fromAddress);
994
          NewRx (p, tcpHeader, fromAddress, toAddress);
1024
          return true;
995
          return true;
1025
        }
996
        }
1026
      // Now we need to see if any data came with the FIN
997
      // Now we need to see if any data came with the FIN
1027
      // if so, call NewRx
998
      // if so, call NewRx
1028
      if (p->GetSize () != 0)
999
      if (p->GetSize () != 0)
1029
        {
1000
        {
1030
          NewRx (p, tcpHeader, fromAddress);
1001
          NewRx (p, tcpHeader, fromAddress, toAddress);
1031
        }
1002
        }
1032
      ++m_nextRxSequence; //bump this to account for the FIN
1003
      ++m_nextRxSequence; //bump this to account for the FIN
1033
      States_t saveState = m_state; // Used to see if app responds
1004
      States_t saveState = m_state; // Used to see if app responds
 Lines 1059-1065    Link Here 
1059
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
1030
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
1060
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
1031
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
1061
      m_connected = true; // ! This is bogus; fix when we clone the tcp
1032
      m_connected = true; // ! This is bogus; fix when we clone the tcp
1062
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
1033
      m_endPoint->SetPeer (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort());
1063
      //treat the connection orientation final ack as a newack
1034
      //treat the connection orientation final ack as a newack
1064
      CommonNewAck (tcpHeader.GetAckNumber (), true);
1035
      CommonNewAck (tcpHeader.GetAckNumber (), true);
1065
      NotifyNewConnectionCreated (this, fromAddress);
1036
      NotifyNewConnectionCreated (this, fromAddress);
 Lines 1070-1090    Link Here 
1070
  return true;
1041
  return true;
1071
}
1042
}
1072
1043
1073
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress)
1044
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress, const Address& toAddress)
1074
{
1045
{
1075
  // Get port and address from peer (connecting host)
1046
  // Get port and address from peer (connecting host)
1076
  m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
1047
  m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom(toAddress).GetIpv4 (),
1077
  m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
1048
                                InetSocketAddress::ConvertFrom(toAddress).GetPort (),
1078
  m_endPoint = m_tcp->Allocate (m_localAddress,
1049
                                InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
1079
                                m_localPort,
1050
                                InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
1080
                                m_remoteAddress,
1081
                                m_remotePort);
1082
  //the cloned socket with be in listen state, so manually change state
1051
  //the cloned socket with be in listen state, so manually change state
1083
  m_state = SYN_RCVD;
1052
  m_state = SYN_RCVD;
1084
  //equivalent to FinishBind
1053
  //equivalent to FinishBind
1085
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
1054
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
1086
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
1055
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
1087
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress);
1056
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress, toAddress);
1088
 }
1057
 }
1089
1058
1090
void TcpSocketImpl::ConnectionSucceeded()
1059
void TcpSocketImpl::ConnectionSucceeded()
 Lines 1146-1152    Link Here 
1146
      header.SetSequenceNumber (m_nextTxSequence);
1115
      header.SetSequenceNumber (m_nextTxSequence);
1147
      header.SetAckNumber (m_nextRxSequence);
1116
      header.SetAckNumber (m_nextRxSequence);
1148
      header.SetSourcePort (m_endPoint->GetLocalPort());
1117
      header.SetSourcePort (m_endPoint->GetLocalPort());
1149
      header.SetDestinationPort (m_remotePort);
1118
      header.SetDestinationPort (m_endPoint->GetPeerPort());
1150
      header.SetWindowSize (AdvertisedWindowSize());
1119
      header.SetWindowSize (AdvertisedWindowSize());
1151
      if (m_shutdownSend)
1120
      if (m_shutdownSend)
1152
        {
1121
        {
 Lines 1166-1172    Link Here 
1166
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
1135
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
1167
      m_tcp->SendPacket (p, header,
1136
      m_tcp->SendPacket (p, header,
1168
                         m_endPoint->GetLocalAddress (),
1137
                         m_endPoint->GetLocalAddress (),
1169
                         m_remoteAddress);
1138
                         m_endPoint->GetPeerAddress());
1170
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
1139
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
1171
      // Notify the application of the data being sent
1140
      // Notify the application of the data being sent
1172
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz);
1141
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz);
 Lines 1224-1230    Link Here 
1224
1193
1225
void TcpSocketImpl::NewRx (Ptr<Packet> p,
1194
void TcpSocketImpl::NewRx (Ptr<Packet> p,
1226
                        const TcpHeader& tcpHeader, 
1195
                        const TcpHeader& tcpHeader, 
1227
                        const Address& fromAddress)
1196
                        const Address& fromAddress,
1197
                        const Address& toAddress)
1228
{
1198
{
1229
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
1199
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
1230
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
1200
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
 Lines 1291-1297    Link Here 
1291
        { // See if we can close now
1261
        { // See if we can close now
1292
          if (m_bufferedData.empty())
1262
          if (m_bufferedData.empty())
1293
            {
1263
            {
1294
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress);
1264
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress, toAddress);
1295
            }
1265
            }
1296
        }
1266
        }
1297
    }
1267
    }
 Lines 1608-1618    Link Here 
1608
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1578
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1609
  tcpHeader.SetAckNumber (m_nextRxSequence);
1579
  tcpHeader.SetAckNumber (m_nextRxSequence);
1610
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1580
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1611
  tcpHeader.SetDestinationPort (m_remotePort);
1581
  tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort());
1612
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1582
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1613
1583
1614
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1584
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1615
    m_remoteAddress);
1585
    m_endPoint->GetPeerAddress());
1616
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
1586
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
1617
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
1587
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
1618
                    << (Simulator::Now () + m_persistTime).GetSeconds());
1588
                    << (Simulator::Now () + m_persistTime).GetSeconds());
 Lines 1673-1684    Link Here 
1673
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1643
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
1674
  tcpHeader.SetAckNumber (m_nextRxSequence);
1644
  tcpHeader.SetAckNumber (m_nextRxSequence);
1675
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1645
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
1676
  tcpHeader.SetDestinationPort (m_remotePort);
1646
  tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort());
1677
  tcpHeader.SetFlags (flags);
1647
  tcpHeader.SetFlags (flags);
1678
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1648
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
1679
1649
1680
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1650
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
1681
    m_remoteAddress);
1651
    m_endPoint->GetPeerAddress());
1682
}
1652
}
1683
1653
1684
void
1654
void
(-)a/src/internet-stack/tcp-socket-impl.h (-9 / +6 lines)
 Lines 100-106    Link Here 
100
  friend class Tcp;
100
  friend class Tcp;
101
  // invoked by Tcp class
101
  // invoked by Tcp class
102
  int FinishBind (void);
102
  int FinishBind (void);
103
  void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
103
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
104
  void Destroy (void);
104
  void Destroy (void);
105
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
105
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
106
  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
106
  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
 Lines 113-122    Link Here 
113
                      Ipv4Address saddr, Ipv4Address daddr);
113
                      Ipv4Address saddr, Ipv4Address daddr);
114
  bool ProcessPacketAction (Actions_t a, Ptr<Packet> p,
114
  bool ProcessPacketAction (Actions_t a, Ptr<Packet> p,
115
                                       const TcpHeader& tcpHeader,
115
                                       const TcpHeader& tcpHeader,
116
                                       const Address& fromAddress);
116
                                       const Address& fromAddress,
117
                                       const Address& toAddress);
117
  Actions_t ProcessEvent (Events_t e);
118
  Actions_t ProcessEvent (Events_t e);
118
  bool SendPendingData(bool withAck = false);
119
  bool SendPendingData(bool withAck = false);
119
  void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress);
120
  void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
120
  void ConnectionSucceeded();
121
  void ConnectionSucceeded();
121
  
122
  
122
  //methods for window management
123
  //methods for window management
 Lines 130-136    Link Here 
130
  uint16_t AdvertisedWindowSize();
131
  uint16_t AdvertisedWindowSize();
131
132
132
  // Manage data tx/rx
133
  // Manage data tx/rx
133
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address&);
134
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
134
  void RxBufFinishInsert (SequenceNumber);
135
  void RxBufFinishInsert (SequenceNumber);
135
  Ptr<TcpSocketImpl> Copy ();
136
  Ptr<TcpSocketImpl> Copy ();
136
  virtual void NewAck (SequenceNumber seq); 
137
  virtual void NewAck (SequenceNumber seq); 
 Lines 177-187    Link Here 
177
  Ipv4EndPoint *m_endPoint;
178
  Ipv4EndPoint *m_endPoint;
178
  Ptr<Node> m_node;
179
  Ptr<Node> m_node;
179
  Ptr<TcpL4Protocol> m_tcp;
180
  Ptr<TcpL4Protocol> m_tcp;
180
  Ipv4Address m_remoteAddress;
181
181
  uint16_t m_remotePort;
182
  //these two are so that the socket/endpoint cloning works
183
  Ipv4Address m_localAddress;
184
  uint16_t m_localPort;
185
  enum SocketErrno m_errno;
182
  enum SocketErrno m_errno;
186
  bool m_shutdownSend;
183
  bool m_shutdownSend;
187
  bool m_shutdownRecv;
184
  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 556-564    Link Here 
556
}
556
}
557
557
558
void 
558
void 
559
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
559
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
560
{
560
{
561
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
561
  NS_LOG_FUNCTION (this << packet << saddr << daddr << port);
562
562
563
  if (m_shutdownRecv)
563
  if (m_shutdownRecv)
564
    {
564
    {
 Lines 566-572    Link Here 
566
    }
566
    }
567
  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
567
  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
568
    {
568
    {
569
      Address address = InetSocketAddress (ipv4, port);
569
      Address address = InetSocketAddress (saddr, port);
570
      SocketAddressTag tag;
570
      SocketAddressTag tag;
571
      tag.SetAddress (address);
571
      tag.SetAddress (address);
572
      packet->AddPacketTag (tag);
572
      packet->AddPacketTag (tag);
(-)a/src/internet-stack/udp-socket-impl.h (-1 / +1 lines)
 Lines 97-103    Link Here 
97
  friend class UdpSocketFactory;
97
  friend class UdpSocketFactory;
98
  // invoked by Udp class
98
  // invoked by Udp class
99
  int FinishBind (void);
99
  int FinishBind (void);
100
  void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
100
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
101
  void Destroy (void);
101
  void Destroy (void);
102
  int DoSend (Ptr<Packet> p);
102
  int DoSend (Ptr<Packet> p);
103
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
103
  int DoSendTo (Ptr<Packet> p, const Address &daddr);

Return to bug 748