~openwns-possum/openwns-wimac/changedProbeName

« back to all changes in this revision

Viewing changes to src/scheduler/ULCallback.cpp

  • Committer: Maciej Muehleisen
  • Date: 2009-05-15 09:53:12 UTC
  • Revision ID: mue@comnets.rwth-aachen.de-20090515095312-68hvhapb4nsuglon
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * This file is part of openWNS (open Wireless Network Simulator)
 
3
 * _____________________________________________________________________________
 
4
 *
 
5
 * Copyright (C) 2004-2009
 
6
 * Chair of Communication Networks (ComNets)
 
7
 * Kopernikusstr. 5, D-52074 Aachen, Germany
 
8
 * phone: ++49-241-80-27910,
 
9
 * fax: ++49-241-80-22242
 
10
 * email: info@openwns.org
 
11
 * www: http://www.openwns.org
 
12
 * _____________________________________________________________________________
 
13
 *
 
14
 * openWNS is free software; you can redistribute it and/or modify it under the
 
15
 * terms of the GNU Lesser General Public License version 2 as published by the
 
16
 * Free Software Foundation;
 
17
 *
 
18
 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
 
19
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 
20
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 
21
 * details.
 
22
 *
 
23
 * You should have received a copy of the GNU Lesser General Public License
 
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
 *
 
26
 ******************************************************************************/
 
27
 
 
28
#include <WIMAC/scheduler/ULCallback.hpp>
 
29
#include <WNS/ldk/Layer.hpp>
 
30
#include <WNS/scheduler/RegistryProxyInterface.hpp>
 
31
#include <WIMAC/Logger.hpp>
 
32
#include <WIMAC/PhyAccessFunc.hpp>
 
33
#include <WIMAC/PhyUserCommand.hpp>
 
34
#include <WIMAC/PhyUser.hpp>
 
35
 
 
36
 
 
37
STATIC_FACTORY_REGISTER_WITH_CREATOR(
 
38
        wimac::scheduler::ULCallback,
 
39
        wimac::scheduler::Callback,
 
40
        "wimac.scheduler.ULCallback",
 
41
        wns::ldk::FUNConfigCreator );
 
42
 
 
43
using namespace wimac::scheduler;
 
44
 
 
45
ULCallback::ULCallback(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& /*config*/) :
 
46
        Callback(fun),
 
47
        fun_(fun)
 
48
{}
 
49
 
 
50
void
 
51
ULCallback::callBack(wns::scheduler::MapInfoEntryPtr mapInfoEntry)
 
52
{
 
53
  simTimeType startTime = mapInfoEntry->start;
 
54
  simTimeType endTime = mapInfoEntry->end;
 
55
  wns::scheduler::UserID user = mapInfoEntry->user;
 
56
  int userID = user->getNodeID();
 
57
  int fSlot = mapInfoEntry->subBand;
 
58
  int beam = mapInfoEntry->beam;
 
59
  wns::Power txPower = mapInfoEntry->txPower;
 
60
  wns::service::phy::phymode::PhyModeInterfacePtr phyModePtr = mapInfoEntry->phyModePtr;
 
61
  wns::service::phy::ofdma::PatternPtr pattern = mapInfoEntry->pattern;
 
62
  wns::CandI estimatedCandI = mapInfoEntry->estimatedCandI;
 
63
  std::list<wns::ldk::CompoundPtr> compounds = mapInfoEntry->compounds;
 
64
 
 
65
  double rate = phyModePtr->getDataRate();
 
66
 
 
67
  assure(compounds.size() > 0, "Empty compound list");
 
68
  simTimeType pduEndTime = (*(compounds.begin()))->getLengthInBits() / rate;
 
69
  simTimeType pduStartTime = 0.0;
 
70
 
 
71
  // iterate over all compounds in list:
 
72
  for (wns::scheduler::CompoundList::iterator iter=compounds.begin(); iter!=compounds.end(); ++iter)
 
73
  {
 
74
        wns::ldk::CompoundPtr pdu = *iter;
 
75
 
 
76
        assure(pdu != wns::ldk::CompoundPtr(), "Invalid PDU");
 
77
 
 
78
#ifndef WNS_NO_LOGGING
 
79
        std::stringstream m;
 
80
        m <<     ":  direction: UL \n"
 
81
          << "        PDU scheduled for user: " << colleagues.registry->getNameForUser(user) << "\n"
 
82
          << "        Frequency Slot: " << fSlot << "\n"
 
83
          << "        StartTime:      " << pduStartTime << "\n"
 
84
          << "        EndTime:        " << pduEndTime << "\n"
 
85
//        << "        Beamforming:    " << beamforming << "\n"
 
86
          << "        Beam:           " << beam << "\n"
 
87
          << "        Tx Power:       " << txPower;
 
88
        LOG_INFO(fun_->getLayer()->getName(), m.str());
 
89
#endif
 
90
//      pduCount++;
 
91
 
 
92
 
 
93
        /// @todo enable frame plotting again
 
94
//      if (plotFrames) {
 
95
//              // substr(19,2) should deliver the "subscriber station xy"
 
96
 
 
97
//              std::string printID;
 
98
 
 
99
//              if (uplink || measureInterference)
 
100
//                      printID = colleagues.registry->getNameForUser(user);
 
101
//              else
 
102
//                      printID = std::string("");
 
103
//              *plotFiles[fSlot] << startTime << "\t" << endTime << "\t"
 
104
//                                                << float(beam) << "\t" << cidColor/2.0 << "\t\"" << printID << "\"\n";
 
105
 
 
106
//      }
 
107
 
 
108
 
 
109
        //only in beamforming case receive pattern need to be set
 
110
        PatternSetterPhyAccessFunc* patternFunc =
 
111
                new PatternSetterPhyAccessFunc;
 
112
        patternFunc->destination_ = user;
 
113
        patternFunc->patternStart_ = pduStartTime;
 
114
        patternFunc->patternEnd_ = pduEndTime;
 
115
        patternFunc->pattern_ = pattern;
 
116
 
 
117
        // set PhyUser command
 
118
        wimac::PhyUserCommand* phyCommand = dynamic_cast<wimac::PhyUserCommand*>(
 
119
                fun_->getProxy()->activateCommand( pdu->getCommandPool(), friends_.phyUser ) );
 
120
 
 
121
        phyCommand->local.pAFunc_.reset( patternFunc );
 
122
 
 
123
        phyCommand->peer.destination_ = user;
 
124
        wimac::Component* wimacComponent = dynamic_cast<wimac::Component*>(fun_->getLayer());
 
125
        phyCommand->peer.cellID_ = wimacComponent->getCellID();
 
126
        phyCommand->peer.source_ = wimacComponent->getNode();
 
127
        phyCommand->peer.phyModePtr = phyModePtr;
 
128
        //      (wns::SmartPtr<const wns::service::phy::phymode::PhyModeInterface>
 
129
        //       (dynamic_cast<const wns::service::phy::phymode::PhyModeInterface*>(phyMode.clone())));
 
130
 
 
131
        phyCommand->peer.measureInterference_ = true; //measureInterference;
 
132
        phyCommand->peer.estimatedCandI_ = estimatedCandI;
 
133
        phyCommand->magic.sourceComponent_ = wimacComponent;
 
134
 
 
135
        /// @todo enable pduWatch
 
136
        //this->pduWatch(pdu);  // Watch for special compounds to inform its observer
 
137
 
 
138
        scheduledPDUs.push(pdu);
 
139
  
 
140
    simTimeType oldEnd = pduEndTime;
 
141
    pduEndTime = pduEndTime +  pdu->getLengthInBits() / rate;
 
142
    pduStartTime = oldEnd;
 
143
  }
 
144
}
 
145
 
 
146
void ULCallback::deliverNow(wns::ldk::Connector* connector)
 
147
{
 
148
 
 
149
        simTimeType now = wns::simulator::getEventScheduler()->getTime();
 
150
 
 
151
        //if(beamforming)
 
152
        //{
 
153
                while( !scheduledPDUs.empty())
 
154
                {
 
155
                        wns::ldk::CompoundPtr compound =
 
156
                                scheduledPDUs.front();
 
157
                        PhyUserCommand* phyUserCommand =
 
158
                                friends_.phyUser->getCommand( compound->getCommandPool() );
 
159
 
 
160
                        PatternSetterPhyAccessFunc* func =
 
161
                                dynamic_cast<PatternSetterPhyAccessFunc*>(phyUserCommand->local.pAFunc_.get());
 
162
 
 
163
                        func->patternStart_ += now;
 
164
                        func->patternEnd_ += now;
 
165
 
 
166
                        if ( connector->hasAcceptor(scheduledPDUs.front() ) )
 
167
                        {
 
168
                                connector->getAcceptor(scheduledPDUs.front())->sendData(scheduledPDUs.front());
 
169
                                scheduledPDUs.pop();
 
170
                        }
 
171
                        else
 
172
                        {
 
173
                                throw wns::Exception( "Lower FU is not accepting scheduled PDU but is supposed to do so" );
 
174
                        }
 
175
                }
 
176
                //}
 
177
}
 
178
 
 
179
 
 
180