Re: [ostinato] Multiple stream using the API python

195 views
Skip to first unread message

Srivats P

unread,
May 6, 2016, 11:14:34 AM5/6/16
to Fabrice Meyer, ostinato
Haven't tested it, but the below should work I guess.

# add two streams
stream_id = ost_pb.StreamIdList()
stream_id.port_id.CopyFrom(tx_port.port_id[0])
stream_id.stream_id.add().id = 1 # stream 1
stream_id.stream_id.add().id = 2 # stream 2
log.info('adding tx_stream %d' % stream_id.stream_id[0].id)
drone.addStream(stream_id)

# configure the stream#1
stream_cfg = ost_pb.StreamConfigList()
stream_cfg.port_id.CopyFrom(tx_port.port_id[0])
s = stream_cfg.stream.add()
s.stream_id.id = stream_id.stream_id[0].id
s.core.is_enabled = True
s.control.num_packets = 5

# setup stream protocols as mac:eth2:ip4:udp:payload
p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kMacFieldNumber
p.Extensions[mac].dst_mac = 0x001122334455
p.Extensions[mac].src_mac = 0x00aabbccddee

p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kEth2FieldNumber

p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kIp4FieldNumber
# reduce typing by creating a shorter reference to p.Extensions[ip4]
ip = p.Extensions[ip4]
ip.src_ip = 0x01020304
ip.dst_ip = 0x05060708
ip.dst_ip_mode = Ip4.e_im_inc_host

s.protocol.add().protocol_id.id = ost_pb.Protocol.kUdpFieldNumber
s.protocol.add().protocol_id.id = ost_pb.Protocol.kPayloadFieldNumber

# configure the stream#2
stream_cfg = ost_pb.StreamConfigList()
stream_cfg.port_id.CopyFrom(tx_port.port_id[0])
s = stream_cfg.stream.add()
s.stream_id.id = stream_id.stream_id[1].id
s.core.is_enabled = True
s.control.num_packets = 5

# setup stream protocols as mac:eth2:ip4:udp:payload
p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kMacFieldNumber
p.Extensions[mac].dst_mac = 0x001122334455
p.Extensions[mac].src_mac = 0x00aabbccddee

p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kEth2FieldNumber

p = s.protocol.add()
p.protocol_id.id = ost_pb.Protocol.kIp4FieldNumber
# reduce typing by creating a shorter reference to p.Extensions[ip4]
ip = p.Extensions[ip4]
ip.src_ip = 0x01020304
ip.dst_ip = 0x05060708
ip.dst_ip_mode = Ip4.e_im_inc_host

s.protocol.add().protocol_id.id = ost_pb.Protocol.kUdpFieldNumber
s.protocol.add().protocol_id.id = ost_pb.Protocol.kPayloadFieldNumber

log.info('configuring tx_stream %d' % stream_id.stream_id[0].id)
drone.modifyStream(stream_cfg)

Alternatively, you might find
https://github.com/little-dude/simple-ostinato easier to start with.
It's a wrapper around python-ostinato with pretty good documentation.

Srivats

On Fri, May 6, 2016 at 1:45 AM, Fabrice Meyer <fab.f...@gmail.com> wrote:
> Hi everyone,
>
> I'm trying to automatize the process of a traffic generator using the python
> API of Ostinato.
> I want to create multiple stream and run them one after an other. I managed
> to create a single stream and change parameters using the Ostinato doc
> (https://github.com/pstavirs/ostinato/wiki/PythonScripting) but i have no
> idea how to do this and how can you control the stream without the sleep
> like in the example (basically run the stream till whole packets in
> parameters are sent).
>
> Someone have an idea? Some examples?
>
>
>
> --
> Get Ostinato News and Updates on Twitter - Follow @ostinato
> (http://twitter.com/ostinato)
> ---
> You received this message because you are subscribed to the Google Groups
> "ostinato" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ostinato+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://ostinato.org/
@ostinato

Corentin Henry

unread,
May 6, 2016, 1:05:15 PM5/6/16
to ostinato, fab.f...@gmail.com
Fwiw here is what the same thing looks like, with simple-ostinato:

from simple_ostinato import Drone, protocols
# connect to the local drone instance
drone = Drone('localhost')
drone.fetch_ports()

# get the loopback interface
drone.get_port('lo')
loopback = drone.get_port('lo')

# create a new stream
stream = loopback.add_stream()
stream.layers = [
    protocols.Ethernet(source='00:aa:bb:cc:dd:ee', destination='00:11:22:33:44:55'),
    protocols.IPv4(source='1.2.3.4', destination='5.6.7.8'),
    protocols.Udp(),
    protocols.Payload()]
stream.num_packets=5
stream.enable()
stream.save()

# send and capture, and retrieve the stats
loopback.start_capture()
loopback.start_send()
loopback.stop_capture()
stats = loopback.get_stats()

Corentin Henry

unread,
May 6, 2016, 1:17:40 PM5/6/16
to ostinato, fab.f...@gmail.com
I realize my answer does not cover everything you asked.

To send multiple streams with simple-ostinato, create multiple streams and enable them. For example:

for stream in myport.streams:
    stream.enable()
    stream.next = 'GOTO_NEXT'
    stream.save()


Then, calling "start_send" should send all the streams one after another.

myport.start_send()


To control when to stop sending/capturing, there is not other way than the "sleep()" I think... In my tests I use this to make it shorter: https://github.com/little-dude/simple-ostinato/blob/master/tests/utils.py#L118-L128.

Fabrice Meyer

unread,
May 9, 2016, 2:48:38 PM5/9/16
to ostinato, fab.f...@gmail.com
Thank you guys, I just figured out that I can also save stream as Python script on the GUI...

I have an other problem, with drone's process:
Don't know if you are familiar with Mininet but i tried to start drones at the starting of my topology on end-hosts using hosts.cmd("drone&")
Processes start looking on term but when I try to run the python script on a host it can't find the drone till I start it manually on the host

Be glad if you have solution to this.
Reply all
Reply to author
Forward
0 new messages