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

(-)a/src/applications/model/bulk-send-application.cc (-25 / +37 lines)
 Lines 109-114   BulkSendApplication::DoDispose (void) Link Here 
109
  Application::DoDispose ();
109
  Application::DoDispose ();
110
}
110
}
111
111
112
void
113
BulkSendApplication::SetSocket(Ptr<Socket> socket)
114
{
115
  m_socket = socket;
116
}
117
112
// Application Methods
118
// Application Methods
113
void BulkSendApplication::StartApplication (void) // Called at time specified by Start
119
void BulkSendApplication::StartApplication (void) // Called at time specified by Start
114
{
120
{
 Lines 118-150   void BulkSendApplication::StartApplication (void) // Called at time specified by Link Here 
118
  if (!m_socket)
124
  if (!m_socket)
119
    {
125
    {
120
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
126
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
127
    }
128
  // Fatal error if socket type is not NS3_SOCK_STREAM or NS3_SOCK_SEQPACKET
129
  if (m_socket->GetSocketType () != Socket::NS3_SOCK_STREAM &&
130
      m_socket->GetSocketType () != Socket::NS3_SOCK_SEQPACKET)
131
    {
132
      NS_FATAL_ERROR ("Using BulkSend with an incompatible socket type. "
133
                      "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
134
                      "In other words, use TCP instead of UDP.");
135
    }
121
136
122
      // Fatal error if socket type is not NS3_SOCK_STREAM or NS3_SOCK_SEQPACKET
137
  if (Inet6SocketAddress::IsMatchingType (m_peer))
123
      if (m_socket->GetSocketType () != Socket::NS3_SOCK_STREAM &&
138
    {
124
          m_socket->GetSocketType () != Socket::NS3_SOCK_SEQPACKET)
139
      m_socket->Bind6 ();
125
        {
140
    }
126
          NS_FATAL_ERROR ("Using BulkSend with an incompatible socket type. "
141
  else if (InetSocketAddress::IsMatchingType (m_peer))
127
                          "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
142
    {
128
                          "In other words, use TCP instead of UDP.");
143
      m_socket->Bind ();
129
        }
144
    }
130
145
131
      if (Inet6SocketAddress::IsMatchingType (m_peer))
146
  m_socket->Connect (m_peer);
132
        {
147
  m_socket->ShutdownRecv ();
133
          m_socket->Bind6 ();
148
  m_socket->SetConnectCallback (
134
        }
149
              MakeCallback (&BulkSendApplication::ConnectionSucceeded, this),
135
      else if (InetSocketAddress::IsMatchingType (m_peer))
150
              MakeCallback (&BulkSendApplication::ConnectionFailed, this));
136
        {
151
  m_socket->SetSendCallback (
137
          m_socket->Bind ();
152
              MakeCallback (&BulkSendApplication::DataSend, this));
138
        }
139
153
140
      m_socket->Connect (m_peer);
141
      m_socket->ShutdownRecv ();
142
      m_socket->SetConnectCallback (
143
        MakeCallback (&BulkSendApplication::ConnectionSucceeded, this),
144
        MakeCallback (&BulkSendApplication::ConnectionFailed, this));
145
      m_socket->SetSendCallback (
146
        MakeCallback (&BulkSendApplication::DataSend, this));
147
    }
148
  if (m_connected)
154
  if (m_connected)
149
    {
155
    {
150
      SendData ();
156
      SendData ();
 Lines 200-205   void BulkSendApplication::SendData (void) Link Here 
200
  // Check if time to close (all sent)
206
  // Check if time to close (all sent)
201
  if (m_totBytes == m_maxBytes && m_connected)
207
  if (m_totBytes == m_maxBytes && m_connected)
202
    {
208
    {
209
      if (! m_dataTransferred.IsNull ())
210
        m_dataTransferred (m_node);
211
203
      m_socket->Close ();
212
      m_socket->Close ();
204
      m_connected = false;
213
      m_connected = false;
205
    }
214
    }
 Lines 229-234   void BulkSendApplication::DataSend (Ptr<Socket>, uint32_t) Link Here 
229
    }
238
    }
230
}
239
}
231
240
232
241
void BulkSendApplication::SetDataTransferredCallback (Callback<void, Ptr<Node> > dataTransferred)
242
{
243
  m_dataTransferred = dataTransferred;
244
}
233
245
234
} // Namespace ns3
246
} // Namespace ns3
(-)a/src/applications/model/bulk-send-application.h (-2 / +22 lines)
 Lines 94-104   public: Link Here 
94
  void SetMaxBytes (uint32_t maxBytes);
94
  void SetMaxBytes (uint32_t maxBytes);
95
95
96
  /**
96
  /**
97
   * \brief Get the socket this application is attached to.
97
   * \brief Get the socket of this application
98
   * \return pointer to associated socket
98
   *
99
   * \return pointer to the socket
99
   */
100
   */
100
  Ptr<Socket> GetSocket (void) const;
101
  Ptr<Socket> GetSocket (void) const;
101
102
103
  /**
104
   * \brief (Optional) Set the application socket
105
   *
106
   * The socket will be created by the application if this
107
   * method is not called.
108
   *
109
   * \param socket Socket pointer
110
   */
111
  void SetSocket (Ptr<Socket> socket);
112
113
  /**
114
   * \brief Set the callback to call when all data has been transmitted
115
   * \param cbDataTransferred Callback
116
   */
117
  void SetDataTransferredCallback (Callback<void, Ptr<Node> >
118
                                   cbDataTransferred);
119
102
protected:
120
protected:
103
  virtual void DoDispose (void);
121
  virtual void DoDispose (void);
104
private:
122
private:
 Lines 106-111   private: Link Here 
106
  virtual void StartApplication (void);    // Called at time specified by Start
124
  virtual void StartApplication (void);    // Called at time specified by Start
107
  virtual void StopApplication (void);     // Called at time specified by Stop
125
  virtual void StopApplication (void);     // Called at time specified by Stop
108
126
127
  Callback<void, Ptr<Node> > m_dataTransferred;  //!< callback to call when all
128
                                                 // data has been transmitted
109
  /**
129
  /**
110
   * \brief Send data until the L4 transmission buffer is full.
130
   * \brief Send data until the L4 transmission buffer is full.
111
   */
131
   */
(-)a/src/applications/model/onoff-application.cc (-14 / +22 lines)
 Lines 142-147   OnOffApplication::DoDispose (void) Link Here 
142
  Application::DoDispose ();
142
  Application::DoDispose ();
143
}
143
}
144
144
145
void
146
OnOffApplication::SetSocket(Ptr<Socket> socket)
147
{
148
  m_socket = socket;
149
}
150
145
// Application Methods
151
// Application Methods
146
void OnOffApplication::StartApplication () // Called at time specified by Start
152
void OnOffApplication::StartApplication () // Called at time specified by Start
147
{
153
{
 Lines 151-173   void OnOffApplication::StartApplication () // Called at time specified by Start Link Here 
151
  if (!m_socket)
157
  if (!m_socket)
152
    {
158
    {
153
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
159
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
154
      if (Inet6SocketAddress::IsMatchingType (m_peer))
160
    }
155
        {
161
  if (Inet6SocketAddress::IsMatchingType (m_peer))
156
          m_socket->Bind6 ();
162
    {
157
        }
163
      m_socket->Bind6 ();
158
      else if (InetSocketAddress::IsMatchingType (m_peer) ||
164
    }
159
               PacketSocketAddress::IsMatchingType (m_peer))
165
  else if (InetSocketAddress::IsMatchingType (m_peer) ||
160
        {
166
           PacketSocketAddress::IsMatchingType (m_peer))
161
          m_socket->Bind ();
167
    {
162
        }
168
      m_socket->Bind ();
163
      m_socket->Connect (m_peer);
169
    }
164
      m_socket->SetAllowBroadcast (true);
170
  m_socket->Connect (m_peer);
165
      m_socket->ShutdownRecv ();
171
  m_socket->SetAllowBroadcast (true);
172
  m_socket->ShutdownRecv ();
166
173
167
      m_socket->SetConnectCallback (
174
  m_socket->SetConnectCallback (
168
        MakeCallback (&OnOffApplication::ConnectionSucceeded, this),
175
        MakeCallback (&OnOffApplication::ConnectionSucceeded, this),
169
        MakeCallback (&OnOffApplication::ConnectionFailed, this));
176
        MakeCallback (&OnOffApplication::ConnectionFailed, this));
170
    }
177
171
  m_cbrRateFailSafe = m_cbrRate;
178
  m_cbrRateFailSafe = m_cbrRate;
172
179
173
  // Insure no pending event
180
  // Insure no pending event
 Lines 293-298   void OnOffApplication::SendPacket () Link Here 
293
                   << " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPort ()
300
                   << " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPort ()
294
                   << " total Tx " << m_totBytes << " bytes");
301
                   << " total Tx " << m_totBytes << " bytes");
295
    }
302
    }
303
296
  m_lastStartTime = Simulator::Now ();
304
  m_lastStartTime = Simulator::Now ();
297
  m_residualBits = 0;
305
  m_residualBits = 0;
298
  ScheduleNextTx ();
306
  ScheduleNextTx ();
(-)a/src/applications/model/onoff-application.h (+2 lines)
 Lines 112-117   public: Link Here 
112
   */
112
   */
113
  Ptr<Socket> GetSocket (void) const;
113
  Ptr<Socket> GetSocket (void) const;
114
114
115
  void SetSocket (Ptr<Socket> socket);
116
115
 /**
117
 /**
116
  * \brief Assign a fixed random variable stream number to the random variables
118
  * \brief Assign a fixed random variable stream number to the random variables
117
  * used by this model.
119
  * used by this model.
(-)a/src/applications/model/packet-sink.cc (-15 / +21 lines)
 Lines 105-111   void PacketSink::DoDispose (void) Link Here 
105
  Application::DoDispose ();
105
  Application::DoDispose ();
106
}
106
}
107
107
108
109
// Application Methods
108
// Application Methods
110
void PacketSink::StartApplication ()    // Called at time specified by Start
109
void PacketSink::StartApplication ()    // Called at time specified by Start
111
{
110
{
 Lines 114-134   void PacketSink::StartApplication () // Called at time specified by Start Link Here 
114
  if (!m_socket)
113
  if (!m_socket)
115
    {
114
    {
116
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
115
      m_socket = Socket::CreateSocket (GetNode (), m_tid);
117
      m_socket->Bind (m_local);
116
    }
118
      m_socket->Listen ();
117
119
      m_socket->ShutdownSend ();
118
  m_socket->Bind (m_local);
120
      if (addressUtils::IsMulticast (m_local))
119
  m_socket->Listen ();
120
  m_socket->ShutdownSend ();
121
  if (addressUtils::IsMulticast (m_local))
122
    {
123
      Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
124
      if (udpSocket)
121
        {
125
        {
122
          Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
126
          // equivalent to setsockopt (MCAST_JOIN_GROUP)
123
          if (udpSocket)
127
          udpSocket->MulticastJoinGroup (0, m_local);
124
            {
128
        }
125
              // equivalent to setsockopt (MCAST_JOIN_GROUP)
129
      else
126
              udpSocket->MulticastJoinGroup (0, m_local);
130
        {
127
            }
131
          NS_FATAL_ERROR ("Error: joining multicast on a non-UDP socket");
128
          else
129
            {
130
              NS_FATAL_ERROR ("Error: joining multicast on a non-UDP socket");
131
            }
132
        }
132
        }
133
    }
133
    }
134
134
 Lines 141-146   void PacketSink::StartApplication () // Called at time specified by Start Link Here 
141
    MakeCallback (&PacketSink::HandlePeerError, this));
141
    MakeCallback (&PacketSink::HandlePeerError, this));
142
}
142
}
143
143
144
void
145
PacketSink::SetSocket(Ptr<Socket> socket)
146
{
147
  m_socket = socket;
148
}
149
144
void PacketSink::StopApplication ()     // Called at time specified by Stop
150
void PacketSink::StopApplication ()     // Called at time specified by Stop
145
{
151
{
146
  NS_LOG_FUNCTION (this);
152
  NS_LOG_FUNCTION (this);
(-)a/src/applications/model/packet-sink.h (+2 lines)
 Lines 91-96   public: Link Here 
91
   * \return list of pointers to accepted sockets
91
   * \return list of pointers to accepted sockets
92
   */
92
   */
93
  std::list<Ptr<Socket> > GetAcceptedSockets (void) const;
93
  std::list<Ptr<Socket> > GetAcceptedSockets (void) const;
94
95
  void SetSocket (Ptr<Socket> socket);
94
 
96
 
95
protected:
97
protected:
96
  virtual void DoDispose (void);
98
  virtual void DoDispose (void);

Return to bug 2106