00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #include "udp-echo-helper.h" 00021 #include "ns3/udp-echo-server.h" 00022 #include "ns3/udp-echo-client.h" 00023 #include "ns3/uinteger.h" 00024 00025 namespace ns3 { 00026 00027 UdpEchoServerHelper::UdpEchoServerHelper (uint16_t port) 00028 { 00029 m_factory.SetTypeId (UdpEchoServer::GetTypeId ()); 00030 SetAttribute ("Port", UintegerValue(port)); 00031 } 00032 00033 void 00034 UdpEchoServerHelper::SetAttribute ( 00035 std::string name, 00036 const AttributeValue &value) 00037 { 00038 m_factory.Set (name, value); 00039 } 00040 00041 ApplicationContainer 00042 UdpEchoServerHelper::Install (Ptr<Node> node) const 00043 { 00044 return ApplicationContainer (InstallPriv (node)); 00045 } 00046 00047 ApplicationContainer 00048 UdpEchoServerHelper::Install (NodeContainer c) const 00049 { 00050 ApplicationContainer apps; 00051 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) 00052 { 00053 apps.Add (InstallPriv (*i)); 00054 } 00055 00056 return apps; 00057 } 00058 00059 Ptr<Application> 00060 UdpEchoServerHelper::InstallPriv (Ptr<Node> node) const 00061 { 00062 Ptr<Application> app = m_factory.Create<UdpEchoServer> (); 00063 node->AddApplication (app); 00064 00065 return app; 00066 } 00067 00068 UdpEchoClientHelper::UdpEchoClientHelper (Ipv4Address address, uint16_t port) 00069 { 00070 m_factory.SetTypeId (UdpEchoClient::GetTypeId ()); 00071 SetAttribute ("RemoteAddress", Ipv4AddressValue (address)); 00072 SetAttribute ("RemotePort", UintegerValue (port)); 00073 } 00074 00075 void 00076 UdpEchoClientHelper::SetAttribute ( 00077 std::string name, 00078 const AttributeValue &value) 00079 { 00080 m_factory.Set (name, value); 00081 } 00082 00083 ApplicationContainer 00084 UdpEchoClientHelper::Install (Ptr<Node> node) const 00085 { 00086 return ApplicationContainer (InstallPriv (node)); 00087 } 00088 00089 ApplicationContainer 00090 UdpEchoClientHelper::Install (NodeContainer c) const 00091 { 00092 ApplicationContainer apps; 00093 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) 00094 { 00095 apps.Add (InstallPriv (*i)); 00096 } 00097 00098 return apps; 00099 } 00100 00101 Ptr<Application> 00102 UdpEchoClientHelper::InstallPriv (Ptr<Node> node) const 00103 { 00104 Ptr<Application> app = m_factory.Create<UdpEchoClient> (); 00105 node->AddApplication (app); 00106 00107 return app; 00108 } 00109 00110 } // namespace ns3