Carlos Ferreira | 9 Apr 2012 18:34
Picon

Holding can only be done within the PEM context. How to overcome this?

Hello all!


I'm trying to implement a simple Network Simulator (message passing between agents) and I'm having trouble with the event system of SimPy. Since i can only hold the Process's by using the yield method within the Process PEM function, I'm having trouble in creating a Socket example, where an Agent waits for a Message Receiving.

Can someone help me with this? I'v searched in several advanced SimPy usage examples but I was unable to find an example to follow.


Thanks for any assistance! 

--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Stefan Scherfke | 12 Apr 2012 08:33
Gravatar

Re: Holding can only be done within the PEM context. How to overcome this?

Hi Carlos,

I think its not quite possible to mix SimPy’s event loop with a blocking socket-receive or a network event
loop. You could use two threads, one for the networking and one for Simpy and send a SimPy event to your
process from the networking thread when you receive a message. However, I’m not sure if that would make
sense and if it wouldn’t screw up the simulation time. 

Could you explain your problem in more detail or give some example code?

Cheers,
Stefan

Am 2012-04-09 um 18:34 schrieb Carlos Ferreira:

> Hello all!
> 
> I'm trying to implement a simple Network Simulator (message passing between agents) and I'm having
trouble with the event system of SimPy. Since i can only hold the Process's by using the yield method within
the Process PEM function, I'm having trouble in creating a Socket example, where an Agent waits for a
Message Receiving.
> 
> Can someone help me with this? I'v searched in several advanced SimPy usage examples but I was unable to
find an example to follow.
> 
> 
> Thanks for any assistance! 
> 
> -- 
> 
> Carlos Miguel Ferreira
> Researcher at Telecommunications Institute
> Aveiro - Portugal
> Work E-mail - cmf <at> av.it.pt
> University of Aveiro E-mail -> cmf <at> ua.pt
> MSN Contact -> carlosmf.pt <at> gmail.com
> Skype & GTalk -> carlosmf.pt <at> gmail.com
> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
> 
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
> _______________________________________________
> Simpy-users mailing list
> Simpy-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
Carlos Ferreira | 13 Apr 2012 12:55
Picon

Re: Holding can only be done within the PEM context. How to overcome this?

Hi Stefan! Thanks for your answer. I almost forgot about this post...

Well, I don't have code to show you because that's my problem, I don't know how to implement what I want.

What I really want is to recreate a simply version of the Socket module that python uses, for network Simulation. I wanted to implement in Python, an alternative to NS3 but much more simple (just a simple message passing), with a simple blocking or non-blocking sockets, to emulate TCP and UDP functionality.

With this, I could be able to simulate a Mesh Network of agents, which interact with each other and also, emulate the network links.

My main problem is, every time I develop some complex code which will require the agent to communicate with another agent at some point, I'm unable to simply Hold the agent without issuing the yield command at the context of the PEM.

I truly want to believe that SimPy can actually do this, I just don't really know how... I was unable to find an Advanced Tutorial for simulating network links.


Thanks for your assistance! :)


--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Stefan Scherfke | 17 Apr 2012 08:24
Gravatar

Re: Holding can only be done within the PEM context. How to overcome this?

Do you actually want to send message over the network or just simulated it? If the later is the case, may you
can uses SimEvents to simulates message-received-events.

Am 2012-04-13 um 12:55 schrieb Carlos Ferreira:

> Hi Stefan! Thanks for your answer. I almost forgot about this post...
> 
> Well, I don't have code to show you because that's my problem, I don't know how to implement what I want.
> 
> What I really want is to recreate a simply version of the Socket module that python uses, for network
Simulation. I wanted to implement in Python, an alternative to NS3 but much more simple (just a simple
message passing), with a simple blocking or non-blocking sockets, to emulate TCP and UDP functionality.
> 
> With this, I could be able to simulate a Mesh Network of agents, which interact with each other and also,
emulate the network links.
> 
> My main problem is, every time I develop some complex code which will require the agent to communicate with
another agent at some point, I'm unable to simply Hold the agent without issuing the yield command at the
context of the PEM.
> 
> I truly want to believe that SimPy can actually do this, I just don't really know how... I was unable to find
an Advanced Tutorial for simulating network links.
> 
> 
> Thanks for your assistance! :)
> 
> 
> -- 
> 
> Carlos Miguel Ferreira
> Researcher at Telecommunications Institute
> Aveiro - Portugal
> Work E-mail - cmf <at> av.it.pt
> University of Aveiro E-mail -> cmf <at> ua.pt
> MSN Contact -> carlosmf.pt <at> gmail.com
> Skype & GTalk -> carlosmf.pt <at> gmail.com
> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
> 
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2_______________________________________________
> Simpy-users mailing list
> Simpy-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Carlos Ferreira | 17 Apr 2012 22:22
Picon

Holding can only be done within the PEM context. How to overcome this?


My objective is to simulate not only the network communication between several agents but also, to have the agents processing the messages and react according to the information within those messages. 

Ok a simple example would be, to simulate the packet exchange and processing for the Spanning Tree Protocol in a Switch Mesh Network.


--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Carlos Ferreira | 18 Apr 2012 12:12
Picon

Re: Holding can only be done within the PEM context. How to overcome this?

(I'm sorry about the double post, but since the answers are not appearing as a single e-mail on my e-mail box but rather trough the digestive message, I copied the wrong e-mail subject)

My objective is to simulate not only the network communication between several agents but also, to have the agents processing the messages and react according to the information within those messages. 


Ok a simple example would be, to simulate the packet exchange and processing for the Spanning Tree Protocol in a Switch Mesh Network. 


Thank you for the assistance!
--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Carlos Ferreira | 5 May 2012 03:01
Picon

Re: Holding can only be done within the PEM context. How to overcome this?

Help? :)

On 18 April 2012 11:12, Carlos Ferreira <carlosmf.pt <at> gmail.com> wrote:
(I'm sorry about the double post, but since the answers are not appearing as a single e-mail on my e-mail box but rather trough the digestive message, I copied the wrong e-mail subject)


My objective is to simulate not only the network communication between several agents but also, to have the agents processing the messages and react according to the information within those messages. 


Ok a simple example would be, to simulate the packet exchange and processing for the Spanning Tree Protocol in a Switch Mesh Network. 


Thank you for the assistance!
--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com




--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Steven Kennedy | 5 May 2012 10:03
Picon
Gravatar

Re: Holding can only be done within the PEM context. How to overcome this?

Hi Carlos,

Not sure what you are after. You have stated your objective, but
haven't asked any specific questions.

Steve

On Sat, May 5, 2012 at 11:01 AM, Carlos Ferreira <carlosmf.pt <at> gmail.com> wrote:
> Help? :)
>
>
> On 18 April 2012 11:12, Carlos Ferreira <carlosmf.pt <at> gmail.com> wrote:
>>
>> (I'm sorry about the double post, but since the answers are
>> not appearing as a single e-mail on my e-mail box but rather trough the
>> digestive message, I copied the wrong e-mail subject)
>>
>>
>> My objective is to simulate not only the network communication between
>> several agents but also, to have the agents processing the messages and
>> react according to the information within those messages.
>>
>>
>> Ok a simple example would be, to simulate the packet exchange and
>> processing for the Spanning Tree Protocol in a Switch Mesh Network.
>>
>>
>> Thank you for the assistance!
>> --
>>
>> Carlos Miguel Ferreira
>> Researcher at Telecommunications Institute
>> Aveiro - Portugal
>> Work E-mail - cmf <at> av.it.pt
>> University of Aveiro E-mail -> cmf <at> ua.pt
>> MSN Contact -> carlosmf.pt <at> gmail.com
>> Skype & GTalk -> carlosmf.pt <at> gmail.com
>> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
>>
>
>
>
> --
>
> Carlos Miguel Ferreira
> Researcher at Telecommunications Institute
> Aveiro - Portugal
> Work E-mail - cmf <at> av.it.pt
> University of Aveiro E-mail -> cmf <at> ua.pt
> MSN Contact -> carlosmf.pt <at> gmail.com
> Skype & GTalk -> carlosmf.pt <at> gmail.com
> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Simpy-users mailing list
> Simpy-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Carlos Ferreira | 6 May 2012 04:22
Picon

Re: Holding can only be done within the PEM context. How to overcome this?

Hmm, maybe some miss-communication here. Sorry for that. 

In order for a process to suspend (wait) for some time, a yield has to be issued within the Process PEM. This can be a bit annoying, when simulating a more complex system, like Network Nodes which exchange packets. 

If I have a Process which represents a Network Agent and for which it's PEM represents it's behaviour, I am only able to suspend the process using the yield command when inside the PEM context. If during the PEM execution, a method is called for which will be responsible for example, simulating the sending of a packet and waiting for an other process agent to answer, I am unable to suspend the agent process for which it's PEM called this special method.

So, asking in a direct way, how can I suspend a process for a certain time or special event, that calls from within it's PEM, methods that are responsible for that suspension.

If this is not possible, does anyone know if there is a project that uses SimPy to implement a Network Simulator similar to NS2 or NS3?


Thanks for the assistance!



On 5 May 2012 09:03, Steven Kennedy <stevenkennedy2263 <at> gmail.com> wrote:
Hi Carlos,

Not sure what you are after. You have stated your objective, but
haven't asked any specific questions.

Steve

On Sat, May 5, 2012 at 11:01 AM, Carlos Ferreira <carlosmf.pt <at> gmail.com> wrote:
> Help? :)
>
>
> On 18 April 2012 11:12, Carlos Ferreira <carlosmf.pt <at> gmail.com> wrote:
>>
>> (I'm sorry about the double post, but since the answers are
>> not appearing as a single e-mail on my e-mail box but rather trough the
>> digestive message, I copied the wrong e-mail subject)
>>
>>
>> My objective is to simulate not only the network communication between
>> several agents but also, to have the agents processing the messages and
>> react according to the information within those messages.
>>
>>
>> Ok a simple example would be, to simulate the packet exchange and
>> processing for the Spanning Tree Protocol in a Switch Mesh Network.
>>
>>
>> Thank you for the assistance!
>> --
>>
>> Carlos Miguel Ferreira
>> Researcher at Telecommunications Institute
>> Aveiro - Portugal
>> Work E-mail - cmf <at> av.it.pt
>> University of Aveiro E-mail -> cmf <at> ua.pt
>> MSN Contact -> carlosmf.pt <at> gmail.com
>> Skype & GTalk -> carlosmf.pt <at> gmail.com
>> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
>>
>
>
>
> --
>
> Carlos Miguel Ferreira
> Researcher at Telecommunications Institute
> Aveiro - Portugal
> Work E-mail - cmf <at> av.it.pt
> University of Aveiro E-mail -> cmf <at> ua.pt
> MSN Contact -> carlosmf.pt <at> gmail.com
> Skype & GTalk -> carlosmf.pt <at> gmail.com
> LinkedIn -> http://www.linkedin.com/in/carlosmferreira
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Simpy-users mailing list
> Simpy-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users
>



--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Nicolas Dandrimont | 6 May 2012 09:14
Favicon
Gravatar

Re: Holding can only be done within the PEM context. How to overcome this?

Le 06/05/2012 à 04:22, Carlos Ferreira <carlosmf.pt <at> gmail.com> écrivit :
> Hmm, maybe some miss-communication here. Sorry for that.
> 
> In order for a process to suspend (wait) for some time, a yield has to be
> issued within the Process PEM. This can be a bit annoying, when simulating
> a more complex system, like Network Nodes which exchange packets.
> 
> If I have a Process which represents a Network Agent and for which it's PEM
> represents it's behaviour, I am only able to suspend the process using the
> yield command when inside the PEM context. If during the PEM execution, a
> method is called for which will be responsible for example, simulating the
> sending of a packet and waiting for an other process agent to answer, I am
> unable to suspend the agent process for which it's PEM called this special
> method.
> 
> So, asking in a direct way, how can I suspend a process for a certain time
> or special event, that calls from within it's PEM, methods that are
> responsible for that suspension.

Hello,

SimPy's PEMs are called in python "generators", which simply are
functions that can be interrupted and yield ("return") several values.

To write a "sub-generator", you need to consume each value it yields
with a for loop, as a for loop is the classical way to consume the
values from a generator. See the (pseudo-)code below:

---------------------------
def sub_generator():
    yield "sub-a"
    yield "sub-b"
    yield "sub-c"

def main_generator():
    yield "main-a"
    for value in sub_generator():
        yield value
---------------------------

which is equivalent to:
---------------------------
def main_generator():
    yield "main-a"
    yield "sub-a"
    yield "sub-b"
    yield "sub-c"
---------------------------

I think the next python 3 release includes the "yield from sub_generator()" 
idiom, which is the equivalent of the for loop above and makes it cleaner.

Hope this helps,
--

-- 
Nicolas Dandrimont

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Carlos Ferreira | 6 May 2012 22:27
Picon

Re: Holding can only be done within the PEM context. How to overcome this?

Thanks for the help!

Yes I heard (somewhere else) about the sub-generators addition to the Python 3.3. I just thought there might be another way through SimPy.

Thanks again!

On 6 May 2012 08:14, Nicolas Dandrimont <nicolas.dandrimont <at> crans.org> wrote:
Le 06/05/2012 à 04:22, Carlos Ferreira <carlosmf.pt <at> gmail.com> écrivit :
> Hmm, maybe some miss-communication here. Sorry for that.
>
> In order for a process to suspend (wait) for some time, a yield has to be
> issued within the Process PEM. This can be a bit annoying, when simulating
> a more complex system, like Network Nodes which exchange packets.
>
> If I have a Process which represents a Network Agent and for which it's PEM
> represents it's behaviour, I am only able to suspend the process using the
> yield command when inside the PEM context. If during the PEM execution, a
> method is called for which will be responsible for example, simulating the
> sending of a packet and waiting for an other process agent to answer, I am
> unable to suspend the agent process for which it's PEM called this special
> method.
>
> So, asking in a direct way, how can I suspend a process for a certain time
> or special event, that calls from within it's PEM, methods that are
> responsible for that suspension.

Hello,

SimPy's PEMs are called in python "generators", which simply are
functions that can be interrupted and yield ("return") several values.

To write a "sub-generator", you need to consume each value it yields
with a for loop, as a for loop is the classical way to consume the
values from a generator. See the (pseudo-)code below:

---------------------------
def sub_generator():
   yield "sub-a"
   yield "sub-b"
   yield "sub-c"

def main_generator():
   yield "main-a"
   for value in sub_generator():
       yield value
---------------------------

which is equivalent to:
---------------------------
def main_generator():
   yield "main-a"
   yield "sub-a"
   yield "sub-b"
   yield "sub-c"
---------------------------

I think the next python 3 release includes the "yield from sub_generator()"
idiom, which is the equivalent of the for loop above and makes it cleaner.

Hope this helps,
--
Nicolas Dandrimont



--

Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf <at> av.it.pt
University of Aveiro E-mail -> cmf <at> ua.pt
MSN Contact -> carlosmf.pt <at> gmail.com
Skype & GTalk -> carlosmf.pt <at> gmail.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users

Gmane