![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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. 5, 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 <WNS/ldk/probe/bus/Packet.hpp> 00029 #include <WNS/probe/bus/ContextProvider.hpp> 00030 #include <WNS/probe/bus/utils.hpp> 00031 #include <WNS/ldk/Layer.hpp> 00032 00033 using namespace wns::ldk; 00034 using namespace wns::ldk::probe::bus; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00037 wns::ldk::probe::bus::Packet, 00038 wns::ldk::probe::Probe, 00039 "wns.probe.PacketProbeBus", 00040 FUNConfigCreator); 00041 00042 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00043 wns::ldk::probe::bus::Packet, 00044 wns::ldk::FunctionalUnit, 00045 "wns.probe.PacketProbeBus", 00046 FUNConfigCreator); 00047 00048 Packet::Packet(fun::FUN* fuNet, const wns::pyconfig::View& config) : 00049 fu::Plain<Packet, PacketCommand>(fuNet), 00050 Forwarding<Packet>(), 00051 logger(config.get("logger")) 00052 { 00053 // read the localIDs from the config 00054 wns::probe::bus::ContextProviderCollection registry(&fuNet->getLayer()->getContextProviderCollection()); 00055 for (int ii = 0; ii<config.len("localIDs.keys()"); ++ii) 00056 { 00057 std::string key = config.get<std::string>("localIDs.keys()",ii); 00058 unsigned long int value = config.get<unsigned long int>("localIDs.values()",ii); 00059 registry.addProvider(wns::probe::bus::contextprovider::Constant(key, value)); 00060 MESSAGE_SINGLE(VERBOSE, logger, "Using Local IDName '"<<key<<"' with value: "<<value); 00061 } 00062 00063 delayIncoming = wns::probe::bus::collector(registry, config, "incomingDelayProbeName"); 00064 delayOutgoing = wns::probe::bus::collector(registry, config, "outgoingDelayProbeName"); 00065 throughput = wns::probe::bus::collector(registry, config, "incomingThroughputProbeName"); 00066 sizeOutgoing = wns::probe::bus::collector(registry, config, "outgoingSizeProbeName"); 00067 sizeIncoming = wns::probe::bus::collector(registry, config, "incomingSizeProbeName"); 00068 } // Packet 00069 00070 Packet::~Packet() 00071 {} 00072 00073 void 00074 Packet::processOutgoing(const CompoundPtr& compound) 00075 { 00076 PacketCommand* command = activateCommand(compound->getCommandPool()); 00077 const simTimeType now = wns::simulator::getEventScheduler()->getTime(); 00078 00079 // record that we processed this compound 00080 long int compoundLength = getLengthInBits(compound); 00081 if(sizeOutgoing) 00082 sizeOutgoing->put(compound, compoundLength); 00083 00084 // record outgoing timestamp for delay probe 00085 command->magic.t = now; 00086 command->magic.probingFU = this; 00087 00088 MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); 00089 m << " sent " << command->magic.t << ", size " << compoundLength; 00090 MESSAGE_END(); 00091 00092 Forwarding<Packet>::processOutgoing(compound); 00093 } // processOutgoing 00094 00095 00096 void 00097 Packet::processIncoming(const CompoundPtr& compound) 00098 { 00099 PacketCommand* command = getCommand(compound->getCommandPool()); 00100 simTimeType now = wns::simulator::getEventScheduler()->getTime(); 00101 long int compoundLength = getLengthInBits(compound); 00102 00103 MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); 00104 m << " sent " << command->magic.t 00105 << " received " << now 00106 << " delay " << now - command->magic.t 00107 << " length " << compoundLength; 00108 MESSAGE_END(); 00109 00110 double travelTime = now - command->magic.t; 00111 assure(travelTime > 0.0, "packet with no travel time."); 00112 00113 if(throughput) 00114 throughput->put(compound, compoundLength / travelTime); 00115 00116 // delay/size probes 00117 if(delayIncoming) 00118 delayIncoming->put(compound, travelTime); 00119 00120 if(delayOutgoing) 00121 command->magic.probingFU->delayOutgoing->put(compound, travelTime); 00122 00123 if(sizeIncoming) 00124 sizeIncoming->put(compound, compoundLength); 00125 00126 Forwarding<Packet>::processIncoming(compound); 00127 } // processIncoming 00128 00129 00130
1.5.5