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