Hi Murphy,

Works like a charm! I was a novice on generators and yield but now I know
that its a great thing!

Thanks for all your help!

Have a Great Day!

Regards,

Vinay Pai B.H.


On Wed, Oct 30, 2013 at 1:58 AM, Murphy McCauley
<[email protected]>wrote:

> On Oct 30, 2013, at 12:47 AM, vinay pai <[email protected]> wrote:
>
> Hi Murphy,
>
> Thanks alot for the immediate response!
>
> This certainly helped me but I am hitting another snag when using Task and
> unfortunately theres not alot of documentation so I would be grateful if
> you could help me out on this.
>
>
> Yeah, recoco is probably the worst-documented aspect of POX.  Colin Scott
> wrote a little examples.py, but I think that's almost all that exists.
>  Hopefully someone will eventually do something about it, though most of
> the time it's largely ignored and people get away with just using timers
> and IOWorker which hide what's going on underneath.
>
> Please see attachment for code. What I am trying to achieve is automate
> for all possible combination of matches using bit manipulation and then in
> turn use all actions for L2 headers.
>
> But the problems I am facing are:
> >>The Task is getting executed twice. I really dont understand why
>
>
> It's because the run method should actually be a generator (it must have a
> "yield").  If it's not, this oddity appears.  I've just pushed a commit to
> dart which asserts that it is in hopes that this will help people spot the
> problem in the future (your code would fail the assertion).
>
> The issue is that you've made *app()* the generator instead of run().  To
> fix this, un-nest the yield (or re-yield the yield).  Here's one way to do
> it:
>
> @@ -79,7 +79,7 @@
>          print "flow Sent"
>          count[index] -= 1
>          print "Value of Count",count[index]
> -        yield Sleep(2)
> +        yield
>          #if (count[index] == 0): return False
>
>      global count
> @@ -91,9 +91,10 @@
>      print count
>      #Timer(2, app, recurring = True, args=["port",0])
>      #Timer(2, app, recurring = True, args=["controller",1])
> -    app("port",0)
> -    #yield Sleep(10)
> -    app("controller",1)
> +    for _ in app("port",0):
> +      yield Sleep(2)
> +    for _ in app("controller",1):
> +      yield Sleep(2)
>
>  class my_learning (object):
>    def __init__ (self):
> @@ -107,7 +108,7 @@
>      Connection = event.connection
>      #t = MyTask(event.connection)
>      t = MyTask()
> -    #t.start()
> +    t.start()
>
>  def launch ():
>    print "calling launch"
>
> >>When Connection is being called, an error is thrown suggesting its
> NoneType and has no attribute "send".
>
>
> Try the above fix and see if it works as expected now (seems to for me).
>
> Thanks alot for your response again and please let me know if I am missing
> something painfully obvious because i have tried every permutation and
> combination but am not able to understand why it is being called twice or
> how to bypass the connection object error.
>
> Regards,
>
> Vinay Pai B.H.
>
>
> On Tue, Oct 29, 2013 at 12:23 AM, Murphy McCauley <
> [email protected]> wrote:
>
>> Timers are independent, so what you are seeing is the expected behavior.
>>
>> How is your "X" factoring into the example?  It appears they should
>> continue forever... unless you have something (not shown) which cancels
>> them.  If so, that's pretty much the answer to your question: to get them
>> to be sequential, when you cancel the first one, start the second one one.
>>  You could have a "to do" list to give it a bit more structure (where each
>> time the Timer executes, you check the to do list).
>>
>> But I think using a Timer may just not be the easiest way to go about
>> doing what you want.  You may be better off just writing a Task to do it.
>>  Here's an example which does one thing seven times, does another three
>> times, and waits for two seconds between each.
>>
>> from pox.lib.recoco import Task, Sleep
>>
>> class MyTask (Task):
>>   def run (self):
>>     for _ in range(7):
>>       print "Thing 1"
>>       yield Sleep(2)
>>
>>     for _ in range(3):
>>       print "Thing 2"
>>       yield Sleep(2)
>>
>>
>> def launch ():
>>   t = MyTask()
>>   t.start()
>>
>> Hope that helps.
>>
>> -- Murphy
>>
>> On Oct 28, 2013, at 11:14 PM, vinay pai <[email protected]> wrote:
>>
>> Hi All,
>>
>> I am trying to write an application which automates and pushes flows so
>> that I can test the functionality of my switch. However I am encountering a
>> small problem.
>>
>> What I am trying to achieve is as follows:
>>
>> <call *function_1()* 'X' times with a timeout of 'Y' seconds with *arguments
>> 'J' and 'K'*>
>> <call *function_1()* 'X' times with a timeout of 'Y' seconds with *arguments
>> 'L' and 'M'*>
>> ...and so on
>>
>> Python code wise:
>>
>> Timer(10,app,recurring = True, args=["port",0])
>> Timer(10,app,recurring = True, args=["controller",1])
>> ...and so on
>>
>> (Here Y = 10 seconds)
>>
>> What I was expecting to see was app() function gets called X times with a
>> timeout of 10 seconds and the arguments as "port" and 0. Next app()
>> function with arguments "controller" and 1 gets called and so on.
>>
>> What I am seeing is both versions of app() function (with different
>> arguments) get called at the same time and wait for 10 seconds and get
>> called again at the same time, for X number of times.
>>
>> Is this the expected behavior for Timer? Is there an alternative where in
>> I can go sequentially? even if I embed the second Timer call in a function
>> and call that function after the first Timer function, both get called at
>> the same time.
>>
>> I have done git clone yesterday so I think its safe to say I am using the
>> latest version.
>> Currently I am running this program against Mininet Version 2.0.0
>>
>> There's less documentation with respect to Timer because of which I am
>> not sure if I am missing something very obvious. Any help will be greatly
>> appreciated.
>>
>> Regards,
>>
>> Vinay Pai B.H.
>>
>> --
>> Vinay Pai B.H.
>> Grad Student - Computer Science
>> Viterbi School of Engineering
>> University of Southern California
>> Los Angeles, CA, USA
>>
>>
>>
>
>
> --
> Vinay Pai B.H.
> Grad Student - Computer Science
> Viterbi School of Engineering
> University of Southern California
> Los Angeles, CA, USA
>  <automate.py>
>
>
>


-- 
Vinay Pai B.H.
Grad Student - Computer Science
Viterbi School of Engineering
University of Southern California
Los Angeles, CA, USA

Reply via email to