How to add payload using python script

607 views
Skip to first unread message

han wang

unread,
Feb 12, 2015, 8:26:29 PM2/12/15
to osti...@googlegroups.com
Hello Experts,

I am using Ostinato as traffic generator to replace Ixia in our lab.

I am able to add eth addresses and ip addresses using the pythonScripting lib , but stuck at adding payload.

Using python scripts, how do we add our own payload for IP packet? 

I tried following code, but payload of the IP packet sent out are all hex value 0s

    p = s.protocol.add()
    p.protocol_id.id = ost_pb.Protocol.kUserScriptFieldNumber
    p.Extensions[userScript].program = "ABABABA"


Can anyone provide some advice on how to do this for L3 IP packet?  Thank you.



Han

Srivats P

unread,
Feb 13, 2015, 9:58:49 AM2/13/15
to han wang, ostinato
Han,

diff -r 21a7f243a4c9 binding/example.py
--- a/binding/example.py Fri Jan 16 20:29:11 2015 +0530
+++ b/binding/example.py Fri Feb 13 20:27:43 2015 +0530
@@ -12,6 +12,7 @@
from core import ost_pb, DroneProxy
from protocols.mac_pb2 import mac
from protocols.ip4_pb2 import ip4, Ip4
+from protocols.payload_pb2 import payload, Payload

# initialize defaults
use_defaults = False
@@ -132,7 +133,11 @@
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
+ #s.protocol.add().protocol_id.id = ost_pb.Protocol.kPayloadFieldNumber
+ p = s.protocol.add()
+ p.protocol_id.id = ost_pb.Protocol.kPayloadFieldNumber
+ p.Extensions[payload].pattern_mode = Payload.e_dp_fixed_word;
+ p.Extensions[payload].pattern = 0xa1b2c3d4;

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


Srivats
> --
> 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 post to this group, send email to osti...@googlegroups.com
> To unsubscribe from this group, send email to
> ostinato+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ostinato?hl=en
> ---
> 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
Message has been deleted

han wang

unread,
Feb 13, 2015, 4:42:48 PM2/13/15
to osti...@googlegroups.com, wangha...@gmail.com
Hi Srivats,

Thanks for your reply.

I am able to modify the payload using your method, but only one word/pattern  repeatedly. Is there a way to modify the whole payloads? We need to send some packets with special payloads to verify some patterns of the network.

Best,
Han 

Srivats P

unread,
Feb 13, 2015, 11:20:28 PM2/13/15
to han wang, ostinato
You need to use the hexDump protocol -

diff --git a/binding/example.py b/binding/example.py
--- a/binding/example.py
+++ b/binding/example.py
@@ -12,6 +12,7 @@ import time
from core import ost_pb, DroneProxy
from protocols.mac_pb2 import mac
from protocols.ip4_pb2 import ip4, Ip4
+from protocols.hexdump_pb2 import hexDump

# initialize defaults
use_defaults = False
@@ -132,7 +133,10 @@ try:
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
+ #s.protocol.add().protocol_id.id = ost_pb.Protocol.kPayloadFieldNumber
+ p = s.protocol.add()
+ p.protocol_id.id = ost_pb.Protocol.kHexDumpFieldNumber
+ p.Extensions[hexDump].content = '\xa1\xb2\xc3\xd4\xe5\xf6';

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

On Sat, Feb 14, 2015 at 1:32 AM, han wang <wangha...@gmail.com> wrote:
> Hi Srivats,
>
> Thanks for your reply.
>
> I am able to modify the payload, but only one word/pattern repeatedly. Is
> there a way to modify the whole payloads? We need to send some packets with
> special payloads to verify some patterns of the network.
>
> Best,
> Han
>
> On Friday, February 13, 2015 at 6:58:49 AM UTC-8, Srivats P wrote:
>>

han wang

unread,
Feb 23, 2015, 4:48:00 PM2/23/15
to osti...@googlegroups.com, wangha...@gmail.com
Thanks Srivats,

Is the length of ip payload fixed to 26 bytes? I did not see any related field in HexDump protocol to modify that. Payloads longer than 26bytes will be truncated. 

Best,
Han

Srivats P

unread,
Feb 24, 2015, 9:05:50 AM2/24/15
to han wang, ostinato
The length of ip payload is derived based on the length of the packet
- default length of the packet is 64 bytes.

64 - 4 (FCS) - 14 (ethernet) - 20 (ipv4) = 26 ip payload length.

Increase the length of the packet (stream.core.frame_len) appropriately.

Srivats
Reply all
Reply to author
Forward
0 new messages