User Manual, Developers Guide and API Documentation

UDP.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/UDP.hpp>
00029 #include <SIMPLETL/service/Connection.hpp>
00030 #include <SIMPLETL/Routing.hpp>
00031 #include <SIMPLETL/SimpleTL.hpp>
00032 #include <WNS/service/tl/FlowID.hpp>
00033 #include <WNS/service/qos/QoSClasses.hpp>
00034 #include <WNS/module/Module.hpp>
00035 #include <WNS/logger/Master.hpp>
00036 
00037 using namespace simpletl;
00038 
00039 UDP::UDP(const wns::pyconfig::View& _pyco)
00040     : pyco(_pyco),
00041       eventscheduler(wns::simulator::getEventScheduler()),
00042       registered(false),
00043       logger("SimpleTL", "UDP",
00044              wns::simulator::getMasterLogger())
00045 {
00046     portPool = new wns::service::tl::PortPool(pyco.get<simTimeType>("portUnbindDelay"));
00047 }
00048 
00049 UDP::~UDP()
00050 {
00051     delete portPool;
00052 }
00053 
00054 void UDP::openConnection(wns::service::tl::Port _port,
00055                          wns::service::nl::FQDN _source,
00056                          wns::service::nl::FQDN _peerInstance,
00057                         wns::service::qos::QoSClass /*_qosClass*/,
00058                          wns::service::tl::ConnectionHandler* _ch)
00059 {
00060     wns::service::tl::ConnectionHandler* peerconnectionhandler =
00061         Routing::getService(_peerInstance, _port);
00062 
00063     wns::service::tl::Port sourcePort = portPool->suggestPort();
00064     portPool->bind(sourcePort);
00065 
00066     wns::service::tl::FlowID flowID ( wns::service::nl::Address(_source), sourcePort, wns::service::nl::Address(_peerInstance),_port );
00067     // UDP-Header: 8 Byte, IP-Header: 20 Byte -> 224 Bit
00068     Bit headerLength = 224;
00069 
00070     Connection* local = new Connection(_ch, flowID, headerLength);
00071     Connection* peer = new Connection(peerconnectionhandler, local->swappedFlowID(), headerLength);
00072 
00073     local->setPeer(peer);
00074     peer->setPeer(local);
00075 
00076     MESSAGE_SINGLE(NORMAL, logger, "Opening connection for flow ID: " << flowID);
00077 
00078     _ch->onConnectionEstablished(wns::service::nl::Address(_source), local);
00079 }
00080 
00081 void UDP::closeConnection(wns::service::tl::Connection* _connection)
00082 {
00083     assureType(_connection, Connection*);
00084     Connection* local = static_cast<Connection*>(_connection);
00085 
00086     local->getConnectionHandler()->onConnectionClosed(_connection);
00087 
00088     assureType(_connection, Connection*);
00089     MESSAGE_SINGLE(NORMAL, logger, "Closing connection for flowID: "
00090                    << static_cast<Connection*>(_connection)->getFlowID());
00091     delete _connection;
00092 }
00093 
00094 void UDP::listenOnPort(wns::service::tl::Port _port, wns::service::tl::ConnectionHandler* _ch)
00095 {
00096     wns::service::nl::FQDN domainName =
00097         wns::service::nl::FQDN(pyco.get<std::string>("domainName"));
00098 
00099     if (!registered)
00100     {
00101         Routing::registerIP(domainName);
00102         registered = true;
00103     }
00104 
00105     Routing::setService(domainName, _port, _ch);
00106 }

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