User Manual, Developers Guide and API Documentation

TCP.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <SIMPLETL/service/TCP.hpp>
00029 #include <SIMPLETL/SimpleTL.hpp>
00030 #include <SIMPLETL/service/Connection.hpp>
00031 #include <SIMPLETL/Routing.hpp>
00032 #include <SIMPLETL/events/ConInd.hpp>
00033 #include <SIMPLETL/events/DisconInd.hpp>
00034 #include <SIMPLETL/Medium.hpp>
00035 #include <WNS/service/tl/FlowID.hpp>
00036 #include <WNS/service/qos/QoSClasses.hpp>
00037 #include <WNS/module/Module.hpp>
00038 #include <WNS/logger/Master.hpp>
00039 
00040 using namespace simpletl;
00041 
00042 TCP::TCP(const wns::pyconfig::View& _pyco)
00043     : pyco(_pyco),
00044       eventscheduler(wns::simulator::getEventScheduler()),
00045       registered(false),
00046       logger("SimpleTL", "TCP",
00047              wns::simulator::getMasterLogger())
00048 {
00049     portPool = new wns::service::tl::PortPool(pyco.get<simTimeType>("portUnbindDelay"));
00050 
00051     wns::pyconfig::View pyco =
00052         wns::module::Module<SimpleTL>::getPyConfigView().getView("channel");
00053     channelcapacity = pyco.get<double>("capacity");
00054 }
00055 
00056 TCP::~TCP()
00057 {
00058     delete portPool;
00059 }
00060 
00061 void TCP::openConnection(wns::service::tl::Port _port,
00062                          wns::service::nl::FQDN _source,
00063                          wns::service::nl::FQDN _peerInstance,
00064                          wns::service::qos::QoSClass /*_qosClass*/,
00065                          wns::service::tl::ConnectionHandler* _ch)
00066 {
00067     wns::service::tl::ConnectionHandler* peerconnectionhandler =
00068         Routing::getService(_peerInstance, _port);
00069 
00070     wns::service::tl::Port sourcePort = portPool->suggestPort();
00071     portPool->bind(sourcePort);
00072 
00073     wns::service::tl::FlowID flowID ( wns::service::nl::Address(_source), sourcePort, wns::service::nl::Address(_peerInstance),_port );
00074     // TCP-Header: 20 Byte, IP-Header: 20 Byte -> 320 Bit
00075     Bit headerLength = 320;
00076 
00077     Connection* local = new Connection(_ch, flowID, headerLength);
00078     Connection* peer = new Connection(peerconnectionhandler, local->swappedFlowID(), headerLength);
00079 
00080     MESSAGE_SINGLE(NORMAL, logger, "Opening connection for flow ID: " << flowID);
00081 
00082     local->setPeer(peer);
00083     peer->setPeer(local);
00084 
00085     simTimeType delay = (double)headerLength / (1000*channelcapacity);
00086 
00087     Medium::send(ConInd(local), delay);
00088 }
00089 
00090 void TCP::closeConnection(wns::service::tl::Connection* _connection)
00091 {
00092     assureType(_connection, Connection*);
00093     Connection* local = static_cast<Connection*>(_connection);
00094 
00095     // TCP-Header: 20 Byte, IP-Header: 20 Byte -> 320 Bit
00096     Bit headerLength = 320;
00097     simTimeType delay = (double)headerLength / (1000*channelcapacity);
00098 
00099     assure(local->getPeer(), "Peer entity not available!");
00100     Medium::send(DisconInd(local), delay);
00101 }
00102 
00103 void TCP::listenOnPort(wns::service::tl::Port _port, wns::service::tl::ConnectionHandler* _ch)
00104 {
00105     wns::service::nl::FQDN domainName =
00106         wns::service::nl::FQDN(pyco.get<std::string>("domainName"));
00107 
00108     if (!registered)
00109     {
00110         Routing::registerIP(domainName);
00111         registered = true;
00112     }
00113     Routing::setService(domainName, _port, _ch);
00114 }

Generated on Sat May 26 03:32:14 2012 for openWNS by  doxygen 1.5.5