00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright 2007 University of Washington 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Tom Henderson (tomhend@u.washington.edu) 00019 */ 00020 00021 #ifndef __packet_sink_h__ 00022 #define __packet_sink_h__ 00023 00024 #include "ns3/application.h" 00025 #include "ns3/event-id.h" 00026 #include "ns3/ptr.h" 00027 #include "ns3/traced-callback.h" 00028 #include "ns3/address.h" 00029 00030 namespace ns3 { 00031 00032 class Address; 00033 class Socket; 00034 class Packet; 00035 00036 /** 00037 * \ingroup applications 00038 * \defgroup packetsink PacketSink 00039 * 00040 * This application was written to complement OnOffApplication, but it 00041 * is more general so a PacketSink name was selected. Functionally it is 00042 * important to use in multicast situations, so that reception of the layer-2 00043 * multicast frames of interest are enabled, but it is also useful for 00044 * unicast as an example of how you can write something simple to receive 00045 * packets at the application layer. Also, if an IP stack generates 00046 * ICMP Port Unreachable errors, receiving applications will be needed. 00047 */ 00048 00049 /** 00050 * \ingroup packetsink 00051 * 00052 * \brief Receive and consume traffic generated to an IP address and port 00053 * 00054 * This application was written to complement OnOffApplication, but it 00055 * is more general so a PacketSink name was selected. Functionally it is 00056 * important to use in multicast situations, so that reception of the layer-2 00057 * multicast frames of interest are enabled, but it is also useful for 00058 * unicast as an example of how you can write something simple to receive 00059 * packets at the application layer. Also, if an IP stack generates 00060 * ICMP Port Unreachable errors, receiving applications will be needed. 00061 * 00062 * The constructor specifies the Address (IP address and port) and the 00063 * transport protocol to use. A virtual Receive () method is installed 00064 * as a callback on the receiving socket. By default, when logging is 00065 * enabled, it prints out the size of packets and their address, but 00066 * we intend to also add a tracing source to Receive() at a later date. 00067 */ 00068 class PacketSink : public Application 00069 { 00070 public: 00071 static TypeId GetTypeId (void); 00072 PacketSink (); 00073 00074 virtual ~PacketSink (); 00075 00076 protected: 00077 virtual void DoDispose (void); 00078 private: 00079 // inherited from Application base class. 00080 virtual void StartApplication (void); // Called at time specified by Start 00081 virtual void StopApplication (void); // Called at time specified by Stop 00082 00083 void HandleRead (Ptr<Socket> socket); 00084 void HandleAccept (Ptr<Socket>, const Address& from); 00085 00086 // In the case of TCP, each socket accept returns a new socket, so the 00087 // listening socket is stored seperately from the accepted sockets 00088 Ptr<Socket> m_socket; // Listening socket 00089 std::list<Ptr<Socket> > m_socketList; //the accepted sockets 00090 00091 Address m_local; // Local address to bind to 00092 TypeId m_tid; // Protocol TypeId 00093 TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace; 00094 00095 }; 00096 00097 } // namespace ns3 00098 00099 #endif 00100