~openwns-possum/openwns-wimac/changedProbeName

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*******************************************************************************
 * This file is part of openWNS (open Wireless Network Simulator)
 * _____________________________________________________________________________
 *
 * Copyright (C) 2004-2009
 * Chair of Communication Networks (ComNets)
 * Kopernikusstr. 5, D-52074 Aachen, Germany
 * phone: ++49-241-80-27910,
 * fax: ++49-241-80-22242
 * email: info@openwns.org
 * www: http://www.openwns.org
 * _____________________________________________________________________________
 *
 * openWNS is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License version 2 as published by the
 * Free Software Foundation;
 *
 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/

#include <WIMAC/scheduler/ULCallback.hpp>
#include <WNS/ldk/Layer.hpp>
#include <WNS/scheduler/RegistryProxyInterface.hpp>
#include <WIMAC/Logger.hpp>
#include <WIMAC/PhyAccessFunc.hpp>
#include <WIMAC/PhyUserCommand.hpp>
#include <WIMAC/PhyUser.hpp>


STATIC_FACTORY_REGISTER_WITH_CREATOR(
	wimac::scheduler::ULCallback,
	wimac::scheduler::Callback,
	"wimac.scheduler.ULCallback",
	wns::ldk::FUNConfigCreator );

using namespace wimac::scheduler;

ULCallback::ULCallback(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& /*config*/) :
	Callback(fun),
	fun_(fun)
{}

void
ULCallback::callBack(wns::scheduler::MapInfoEntryPtr mapInfoEntry)
{
  simTimeType startTime = mapInfoEntry->start;
  simTimeType endTime = mapInfoEntry->end;
  wns::scheduler::UserID user = mapInfoEntry->user;
  int userID = user->getNodeID();
  int fSlot = mapInfoEntry->subBand;
  int beam = mapInfoEntry->beam;
  wns::Power txPower = mapInfoEntry->txPower;
  wns::service::phy::phymode::PhyModeInterfacePtr phyModePtr = mapInfoEntry->phyModePtr;
  wns::service::phy::ofdma::PatternPtr pattern = mapInfoEntry->pattern;
  wns::CandI estimatedCandI = mapInfoEntry->estimatedCandI;
  std::list<wns::ldk::CompoundPtr> compounds = mapInfoEntry->compounds;

  double rate = phyModePtr->getDataRate();

  assure(compounds.size() > 0, "Empty compound list");
  simTimeType pduEndTime = (*(compounds.begin()))->getLengthInBits() / rate;
  simTimeType pduStartTime = 0.0;

  // iterate over all compounds in list:
  for (wns::scheduler::CompoundList::iterator iter=compounds.begin(); iter!=compounds.end(); ++iter)
  {
	wns::ldk::CompoundPtr pdu = *iter;

	assure(pdu != wns::ldk::CompoundPtr(), "Invalid PDU");

#ifndef WNS_NO_LOGGING
	std::stringstream m;
	m <<     ":  direction: UL \n"
	  << "        PDU scheduled for user: " << colleagues.registry->getNameForUser(user) << "\n"
	  << "        Frequency Slot: " << fSlot << "\n"
	  << "        StartTime:      " << pduStartTime << "\n"
	  << "        EndTime:        " << pduEndTime << "\n"
//	  << "        Beamforming:    " << beamforming << "\n"
	  << "        Beam:           " << beam << "\n"
	  << "        Tx Power:       " << txPower;
	LOG_INFO(fun_->getLayer()->getName(), m.str());
#endif
//	pduCount++;


	/// @todo enable frame plotting again
// 	if (plotFrames) {
// 		// substr(19,2) should deliver the "subscriber station xy"

// 		std::string printID;

// 		if (uplink || measureInterference)
// 			printID = colleagues.registry->getNameForUser(user);
// 		else
// 			printID = std::string("");
// 		*plotFiles[fSlot] << startTime << "\t" << endTime << "\t"
// 						  << float(beam) << "\t" << cidColor/2.0 << "\t\"" << printID << "\"\n";

// 	}


	//only in beamforming case receive pattern need to be set
	PatternSetterPhyAccessFunc* patternFunc =
		new PatternSetterPhyAccessFunc;
	patternFunc->destination_ = user;
	patternFunc->patternStart_ = pduStartTime;
	patternFunc->patternEnd_ = pduEndTime;
	patternFunc->pattern_ = pattern;

	// set PhyUser command
	wimac::PhyUserCommand* phyCommand = dynamic_cast<wimac::PhyUserCommand*>(
		fun_->getProxy()->activateCommand( pdu->getCommandPool(), friends_.phyUser ) );

	phyCommand->local.pAFunc_.reset( patternFunc );

	phyCommand->peer.destination_ = user;
	wimac::Component* wimacComponent = dynamic_cast<wimac::Component*>(fun_->getLayer());
	phyCommand->peer.cellID_ = wimacComponent->getCellID();
	phyCommand->peer.source_ = wimacComponent->getNode();
	phyCommand->peer.phyModePtr = phyModePtr;
	//	(wns::SmartPtr<const wns::service::phy::phymode::PhyModeInterface>
	//	 (dynamic_cast<const wns::service::phy::phymode::PhyModeInterface*>(phyMode.clone())));

	phyCommand->peer.measureInterference_ = true; //measureInterference;
	phyCommand->peer.estimatedCandI_ = estimatedCandI;
	phyCommand->magic.sourceComponent_ = wimacComponent;

	/// @todo enable pduWatch
	//this->pduWatch(pdu);  // Watch for special compounds to inform its observer

	scheduledPDUs.push(pdu);
  
    simTimeType oldEnd = pduEndTime;
    pduEndTime = pduEndTime +  pdu->getLengthInBits() / rate;
    pduStartTime = oldEnd;
  }
}

void ULCallback::deliverNow(wns::ldk::Connector* connector)
{

	simTimeType now = wns::simulator::getEventScheduler()->getTime();

	//if(beamforming)
	//{
		while( !scheduledPDUs.empty())
		{
			wns::ldk::CompoundPtr compound =
				scheduledPDUs.front();
			PhyUserCommand* phyUserCommand =
				friends_.phyUser->getCommand( compound->getCommandPool() );

			PatternSetterPhyAccessFunc* func =
				dynamic_cast<PatternSetterPhyAccessFunc*>(phyUserCommand->local.pAFunc_.get());

			func->patternStart_ += now;
			func->patternEnd_ += now;

			if ( connector->hasAcceptor(scheduledPDUs.front() ) )
			{
				connector->getAcceptor(scheduledPDUs.front())->sendData(scheduledPDUs.front());
				scheduledPDUs.pop();
			}
			else
			{
				throw wns::Exception( "Lower FU is not accepting scheduled PDU but is supposed to do so" );
			}
		}
		//}
}