7
TRex Stateful Python API Tutorial i TRex Stateful Python API Tutorial

TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

  • Upload
    dotram

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial i

TRex Stateful Python API Tutorial

Page 2: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial ii

REVISION HISTORY

NUMBER DATE DESCRIPTION NAME

Page 3: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial iii

Contents

0.1 TRex traffic generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

0.2 TRex Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

0.2.1 TRex Control Plane - High Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

0.2.2 TRex Control Plane - Example crumbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Page 4: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial 1 / 4

0.1 TRex traffic generator

TRex traffic generator is a tool design the benchmark platforms with realistic traffic. This is a work-in-progress product, whichis under constant developement, new features are added and support for more router’s fuctionality is achieved.

0.2 TRex Control

TRex control plane is under developement, and a phase 1 is planned to be published soon (Apr 2015).This document will shortly describe the planned control plane for TRex, which is planned to be more scalable and supportautomation more intuitively.

0.2.1 TRex Control Plane - High Level

TRex control plane is based on a JSON RPC transactions between clients and server.Each TRex machine will have a server running on it, closely interacting with TRex (clients do not approach TRex directly).As future feature, and as multiple TRexes might run on the same machine, single server shall serve all TRexes running a machine.

The client is a Python based application that created TRexClient instances.Using class methods, the client interacts with TRex server, and enable it to perform the following commands:

1. Start TRex run (custom parameters supported).

2. Stop TRex run.

3. Check what is the TRex status (possible states: Idle, Starting, Running).

4. Poll (by customize sampling) the server and get live results from TRex while still running.

5. Get custom TRex stats based on a window of saved history of latest N polling results.

0.2.2 TRex Control Plane - Example crumbs

• Exmaple #1: Checking TRex status and Launching TRex The following program checks TRex status, and later on launchesit, querying its status along different time slots.

import time

trex = CTRexClient(’trex-name’)print "Before Running, TRex status is: ", trex.is_running() # v1print "Before Running, TRex status is: ", trex.get_running_status() # v2ret = trex.start_trex( c = 2, ←↩

# v3m = 0.1,d = 20,f = ’avl/sfr_delay_10_1g.yaml’,nc = True,p = True,l = 1000)

print "After Starting, TRex status is: ", trex.is_running(), trex.get_running_status()

time.sleep(10) # v4print "Is TRex running? ", trex.is_running(), trex.get_running_status() # v5

Page 5: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial 2 / 4

v1 is_running() returns a boolean and checks if TRex is running or not.v2 get_running_status() returns a Python dictionary with TRex state, along with a verbose field containing extrainfo, if available.v3 TRex lanching. All types of inputs are supported. Some fields (such as f and c are mandatory).v4 Going to sleep for few seconds, allowing TRex to start.v5 Checking out with TRex status again, printing both a boolean return value and a full status.

This code will prompt the following output, assuming a server was launched on the TRex machine.

Connecting to TRex @ http://trex-dan:8090/ ...Before Running, TRex status is: FalseBefore Running, TRex status is: {u’state’: <TRexStatus.Idle: 1>, u’verbose’: u’TRex is ←↩

Idle’} v1 v2After Starting, TRex status is: False {u’state’: <TRexStatus.Starting: 2>, u’verbose’: u’ ←↩

TRex is starting’} v3 v4Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running’}v5 v6v1 , v2 , v3 , v4 , v5 , v6 When looking at TRex status, both an enum status (Idle, Starting, Running) and verbose output are

available.

• Exmaple #2: Checking TRex status and Launching TRex with BAD PARAMETERS The following program checksTRex status, and later on launches it with wrong input (mdf is not legal option), hence TRex run will not start and amessage will be available.

import time

trex = CTRexClient(’trex-name’)print "Before Running, TRex status is: ", trex.is_running() # v1print "Before Running, TRex status is: ", trex.get_running_status() # v2ret = trex.start_trex( c = 2, ←↩

# v3# v4 mdf = 0.1,

d = 20,f = ’avl/sfr_delay_10_1g.yaml’,nc = True,p = True,l = 1000)

print "After Starting, TRex status is: ", trex.is_running(), trex.get_running_status()

time.sleep(10) # v5print "Is TRex running? ", trex.is_running(), trex.get_running_status() # v6v1 is_running() returns a boolean and checks if TRex is running or not.v2 get_running_status() returns a Python dictionary with TRex state, along with a verbose field containing extra

info, if available.v3 TRex lanching. All types of inputs are supported. Some fields (such as f and c are mandatory).

Page 6: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial 3 / 4

v4 Wrong parameter (mdf ) injected.v5 Going to sleep for few seconds, allowing TRex to start.v6 Checking out with TRex status again, printing both a boolean return value and a full status.

This code will prompt the following output, assuming a server was launched on the TRex machine.

Connecting to TRex @ http://trex-dan:8090/ ...Before Running, TRex status is: FalseBefore Running, TRex status is: {u’state’: <TRexStatus.Idle: 1>, u’verbose’: u’TRex is ←↩

Idle’} v1 v2After Starting, TRex status is: False {u’state’: <TRexStatus.Starting: 2>, u’verbose’: u’ ←↩

TRex is starting’} v3 v4Is TRex running? False {u’state’: <TRexStatus.Idle: 1>, u’verbose’: u’TRex run failed due ←↩

to wrong input parameters, or due to reachability issues.’}v5 v6v1 , v2 , v3 , v4 When looking at TRex status, both an enum status (Idle, Starting, Running) and verbose output are

available.v5 , v6 After TRex lanuching failed, a message indicating the failure reason. However, TRex is back Idle, ready to handle anotherlaunching request.

• Exmaple #3: Launching TRex, monitor live data and stopping on demand The following program will launchTRex, and while it runs poll the server (every 5 seconds) for running inforamtion, such as latency, drops, and otherextractable parameters.Then, after some criteria was met, TRex execution is terminated, enabeling others to use the resource instead of waitingfor the entire execution to finish.

print "Before Running, TRex status is: ", trex.get_running_status()

print "Starting TRex..."ret = trex.start_trex( c = 2,

mdf = 0.1,d = 100,f = ’avl/sfr_delay_10_1g.yaml’,nc = True,p = True,l = 1000)

print "After Starting, TRex status is: ", trex.is_running(), trex.get_running_status()print "sleeping 20 secs.."time.sleep(20)for i in range(5):

print "Is TRex running? ", trex.is_running(), trex.get_running_status() # v1# v2 received_info = trex.get_running_info()# v3 # Custom data processing is done here# v4 time.sleep(5)

print "Terminating TRex..."# v5 ret = trex.stop_trex()print "After stopping, TRex status is: ", trex.is_running(), trex.get_running_status() ←↩

# v6v1 Running queries is still optional, although not mandatory in order to get stats.

Page 7: TRex Stateful Python API Tutorial - Cisco · TRex Stateful Python API Tutorial 1 / 4 0.1TRex traffic generator TRex traffic generator is a tool design the benchmark platforms with

TRex Stateful Python API Tutorial 4 / 4

v2 get_running_info() will return the latest data dump available from TRex.Some aditional data manipulation and queries are under developement, including manipulation over number of dumps,which is useful for avoiding "spikes" of singular behavior.v3 Data processing. This is fully customizable for the relevant test initiated.v4 The sampling rate is flexibale and can be configured depending on the desired output.v5 TRex termination.v6 Post-termination check for status.

This code will prompt the following output, assuming a server was launched on the TRex machine.

Connecting to TRex @ http://trex-dan:8090/ ...Before Running, TRex status is: FalseBefore Running, TRex status is: {u’state’: <TRexStatus.Idle: 1>, u’verbose’: u’TRex is ←↩

Idle’}Starting TRex...After Starting, TRex status is: False {u’state’: <TRexStatus.Starting: 2>, u’verbose’: u’ ←↩

TRex is starting’}v1 Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running ←↩’}v2 Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running ←↩’}v3 Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running ←↩’}v4 Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running ←↩’}v5 Is TRex running? True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u’TRex is Running ←↩’}

Before terminating, TRex status is: True {u’state’: <TRexStatus.Running: 3>, u’verbose’: u ←↩’TRex is Running’}

Terminating TRex...# v6 After stopping, TRex status is: False {u’state’: <TRexStatus.Idle: 1>, u’verbose’: u’ ←↩

TRex finished (terminated).’}

v1 , v2 , v3 , v4 , v5 Polling TRex status while in a data polling loop.v6 After termination, we can see that TRex is back idle, also the verbose field shows the stop reason