[Nfd-dev] strategy specific parameters

Klaus Schneider klaus.schneider at uni-bamberg.de
Wed Apr 22 14:37:19 PDT 2015


Hi Junxiao,

Thanks for your comment!

Of course, you are completely correct with your remark. Putting the 
parameters into the strategy makes them global for all strategy 
instances which isn't what we want. Also changing parameters in a method 
called "getStrategy()" wasn't the most logical thing to do.

Here is my new solution to solve this problem:

1. Remove the "n.second->setParameters..." line from the getStrategy() 
method below.

2. Add the parameters to strategy-choice-entry.hpp instead of Strategy.hpp

>   void setParameters(std::string newParameters)
>   {
>     parameters = newParameters;
>   }
>
>   const std::string getParameters()
>   {
>     return parameters;
>   }
>
> private:
>   std::string parameters;

3. In strategy-choice.cpp add this to the end of the 
StrategyChoice::insert() Method:

// Gets the parameters as last element of the name (behind "/").
>   std::string strName = strategyName.toUri();
>   std::vector<std::string> strVector;
>   boost::split(strVector, strName, boost::is_any_of("/"));
>
>   entry->setStrategy(*strategy);
>   entry->setParameters(strVector.back());
>   return true;
> }

Also add a method to access the parameters:

> std::string StrategyChoice::findEffectiveParameters(const Name& prefix) const
> {
>   shared_ptr < name_tree::Entry > nte = m_nameTree.findLongestPrefixMatch(prefix,
>       [] (const name_tree::Entry& entry) {
>         return static_cast<bool>(entry.getStrategyChoiceEntry());
>       });
>
>   BOOST_ASSERT(static_cast<bool>(nte));
>   return nte->getStrategyChoiceEntry()->getParameters();
> }

4. Use the parameters inside the strategy with a reference to the forwarder:

> void YourStrategyName::initialize()
> {
>   if (!init) {
>     init = true;
>     std::string parameters = ownForwarder.getStrategyChoice().findEffectiveParameters(Name("/"));
>     std::cout << "Effective parameters: " << parameters << "\n";
>   }
> }

My first test shows that a new parameter for namespace /A no longer 
overwrites parameters of namespace /.

Of course, it might contain other bugs. For instance, changing 
parameters of the same prefix after the initial insert 
(StrategyChoice::changeStrategy() ) currently doesn't work. However, it 
shouldn't be too hard to fix this.


Thanks for the tip with ns3::GlobalVariable, I have to look at this.

Best regards
Klaus






On 22.04.2015 19:06, Junxiao Shi wrote:
> Hi Klaus
>
> A major flaw of this solution is: you can't use the same strategy with
> different parameters.
> Consider the following setup:
>
>     - namespace=/, strategy=/my-strategy/param=no
>     - namespace=/A , strategy=/my-strategy/param=yes
>
> StrategyChoice::getStrategy returns the same instance (from
> m_strategyInstances), so that the second set of parameters would change the
> state of that instance, and affect both namespaces.
> Since most simulations only deal with one strategy, this shouldn't cause
> big problems.
>
> Given you are only using this in simulations, an easier approach is to pass
> the parameters with a ns3::GlobalVariable.
>
> Yours, Junxiao
>
> On Sun, Apr 19, 2015 at 2:16 PM, Klaus Schneider <
> klaus.schneider at uni-bamberg.de> wrote:
>
>> Here is my quick and dirty solution for including parameters in the
>> strategy name.
>>
>> 2. I changed StrategyChoice::getStrategy() in strategy-choice.cpp to
>>
>>   fw::Strategy*
>>> StrategyChoice::getStrategy(const Name& strategyName) const
>>> {
>>>    fw::Strategy* candidate = nullptr;
>>>    for (auto n : m_strategyInstances) {
>>>      if (strategyName.isPrefixOf(n.first) ||
>>> n.first.isPrefixOf(strategyName)) {
>>>        switch (n.first.size() + 1 - strategyName.size()) {
>>>        case 0: // Strategy with parameters (one element longer than exact
>>> match)
>>>          n.second->setParameters(strategyName.toUri().erase(0,
>>> n.first.toUri().size() + 1));
>>>          return n.second.get();
>>>        case 1:  // exact match
>>>          return n.second.get();
>>>        case 2:  // unversioned strategyName matches versioned strategy
>>>          candidate = n.second.get();
>>>          break;
>>>        }
>>>      }
>>>    }
>>>    return candidate;
>>> }
>>
>>
>

-- 
Klaus Schneider

Mail: klaus.schneider at uni-bamberg.de
LinkedIn: https://www.linkedin.com/in/schneiderklaus



More information about the Nfd-dev mailing list