simple_ostinato package

class simple_ostinato.Drone(host, connect=True)[source]

Bases: object

Wrapper for ostinato.core.DroneProxy.

All the protocol buffer related methods are prefixed with _o_ and are for internal use only.

Parameters:
  • host (str) – ip address or hostname of the host running the drone instance you want to connect to.
  • connect (bool) – if True, attempt to connect to the remote instance when the object is initialized. Otherwise, it can be done manually later with connect()
connect()[source]

Connect to the remote drone instance. By default, it is already called when the object is created.

disconnect()[source]

Disconnect from the remote drone instance.

fetch_ports()[source]

Get the list of all the ports on the remote host. They are stored in the ports dictionnary.

get_port(name)[source]

Get ports from ports by name. If the port is not found, None is returned.

get_port_by_id(port_id)[source]
reconnect()[source]

Reconnect to the remote drone instance.

class simple_ostinato.Port(drone, port_id)[source]

Bases: object

Represent a remote port. This class provides simple methods to add/remove streams, and send/capture traffic.

Parameters:
  • drone (Drone) – an object that wraps the underlying protocol buffer calls.
  • port_id (int) – id of the port.
streams

dict – a dictionnary with all the streams configured on this port. It can be refreshed with fetch_streams().

port_id

int – id of the port

add_stream(*layers)[source]

Create a new stream, on the remote drone instance, and return the corresponding Stream object. The object is also added to streams.

Layers must be instances of simple_ostinato.protocols.Protocol

>>> from simple_ostinato import protocols
>>> my_port.add_stream(protocols.Mac(), protocols.Ethernet())
clear_stats()[source]

Clear the port statistics

del_stream(stream_id)[source]

Delete the stream provided as argument.

Parameters:stream_id (int) – id of the stream to delete from the port.
fetch()[source]

Fetch the current port configuration from the remote drone instance.

fetch_streams()[source]

Fetch the streams configured on this port, from the remote drone instance. The streams are stored in streams.

from_dict(values)[source]
get_capture(save_as=None)[source]

Get the lastest capture and return is as a string.

Parameters:save_as (str) – if provided, the capture will also be saved as a pcap file at the specified location on the host that runs drone.
get_stats()[source]

Fetch the port statistics, and return them as a dictionary.

get_stream(stream_id)[source]

Return a the Stream object corresponding to the given stream ID (int)

get_streams_by_name(name)[source]

Return a list of Stream s that have the given name (:class:str). Since most often names are unique, it is common to get a stream doing:

>>> my_stream_foo = my_port.get_streams_by_name('stream_foo')[0]
save()[source]

Save the current port configuration on the remote drone instance.

save_capture(o_capture_buffer, path)[source]
start_capture()[source]

Start capturing. By default, this method is non-blocking and returns immediately, and stop_send() must be called to stop the capture.

start_send()[source]

Start transmitting the streams that are enabled on this port.

stop_capture()[source]

Stop the current capture

stop_send()[source]

Stop sending

to_dict()[source]
is_enabled

If True the port is enabled. Otherwise, it is disabled.

is_exclusive_control
name

Name of the port. This is a read-only attribute.

port_id

ID of the port. This is a read-only attribute.

transmit_mode

Can be SEQUENTIAL or INTERLEAVED.

user_name

Name of the port user.

class simple_ostinato.Stream(port, stream_id, layers=None)[source]

Bases: object

Represent a stream configured on a port. Besides all the stream configuration parameters, a stream class has layers which define the packets to be sent.

Parameters:
  • port (Port) – the port instance on which the stream is defined.
  • stream_id (int) – the stream ID.
disable()[source]

Disable the stream. It is equivalent to setting is_enabled to False.

enable()[source]

Enable the stream. It is equivalent to setting is_enabled to True.

fetch()[source]

Fetch the stream configuration on the remote drone instance (including all the layers).

from_dict(dictionary)[source]
save()[source]

Save the current stream configuration (including the protocols).

to_dict()[source]
bursts_per_sec

Number of bursts to send per second.

frame_len
frame_len_max
frame_len_min
is_enabled

Return True if the stream is enabled, False otherwise. By default, streams are not enabled.

layers

List of all the layers configured for this stream.

len_mode

Length mode. It must be either FIXED (the default), INC, DEC or RANDOM

mode

Sending mode. It must be either FIXED (the default) or CONTINUOUS.

If set to FIXED, a fixed number of packets or bursts is sent. If unit is set to PACKETS, then num_packets packets are sent. If it is set to BURSTS then num_bursts bursts are sent.

If set to CONTINUOUS, packets or bursts are sent continuously until the port stop transmitting.

name

Name of the stream (optional)

next

What to do after the current stream finishes. It is ignored if mode is set to CONTINUOUS.

  • STOP: stop after this stream
  • GOTO_NEXT: send the next enabled stream
  • GOTO_ID: send a stream with a given ID.
num_bursts

Number of bursts to send. This is ignored if mode is set to CONTINUOUS or if unit is set to PACKETS.

num_packets

Number of packets to send. This is ignored if mode is set to CONTINUOUS or if unit is set to BURSTS.

packets_per_burst

Number of packets per burst. This is ignored if mode is set to CONTINUOUS or if unit is set to PACKETS

packets_per_sec

Number of bursts to send per second.

unit

Unit to send. It must be either PACKETS (the default) or BURSTS.