-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstc_streamblock.py
122 lines (99 loc) · 4.27 KB
/
stc_streamblock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import logging
from sys import maxsize
from time import sleep
from stc_ipv4 import StcIPv4
from stc_ethernetII import StcEthernetII
log = logging.getLogger(__name__)
class StcStreamblockException(Exception):
pass
class StcStreamblock:
default_config = {
"AdvancedInterleavingGroup": "0",
"AllowInvalidHeaders": False,
"BurstSize": "1",
"ByPassSimpleIpSubnetChecking": False,
"ConstantFillPattern": "0",
"CustomPfcPriority": "0",
"EnableBackBoneTrafficSendToSelf": True,
"EnableBidirectionalTraffic": False,
"EnableControlPlane": False,
"EnableCustomPfc": False,
"EnableFcsErrorInsertion": False,
"EnableHighSpeedResultAnalysis": True,
"EnableResolveDestMacAddress": True,
"EnableStreamOnlyGeneration": True,
"EnableTxPortSendingTrafficToSelf": False,
"EndpointMapping": "ONE_TO_ONE",
"FillType": "CONSTANT",
"Filter": "",
"FixedFrameLength": "128",
"FrameConfig": "",
"FrameLengthMode": "FIXED",
"InsertSig": True,
"InterFrameGap": "12",
"Load": "10",
"LoadUnit": "PERCENT_LINE_RATE",
"MaxFrameLength": "256",
"MinFrameLength": "128",
"Priority": "0",
"ShowAllHeaders": False,
"StartDelay": "0",
"StepFrameLength": "1",
"TimeStampOffset": "0",
"TimeStampType": "MIN",
"TrafficPattern": 'PAIR'
}
config_key = 'streamblock'
def __init__(self, handle, port_handle, session):
self._handle = handle
self._port_handle = port_handle
self._session = session
self._config = session.config.data[StcStreamblock.config_key]
def create_ethernetII(self, **kwargs):
# GTL - not sure why giving args to ethII causes things to break...
# GTL - look into this.
# kwargs = self._session.config.data[StcEthernetII.config_key]
# return self._session.create_obj('Ethernet:EthernetII', self._handle, None, **kwargs)
return self._session.create_obj('Ethernet:EthernetII', self._handle)
def create_ipv4(self, **kwargs):
kwargs = self._session.config.data[StcIPv4.config_key]
return self._session.create_obj('ipv4:IPv4', self._handle, None, **kwargs)
def generate_traffic(self):
# GTL - FIX THIS STUPID CLASS DESIGN that req. hardcoding these strings.
sess_conf_key = 'stc_session'
traf_time_key = 'traffic_duration'
if traf_time_key not in self._session.config.data[sess_conf_key]:
t = maxsize
else:
t = self._session.config.data[sess_conf_key][traf_time_key]
self.start_traffic()
log.info('Sleeping {} seconds'.format(t))
sleep(t)
self.stop_traffic()
def start_traffic(self):
'''
Given this stream block, generate traffic via our session for the time given.
This method will block until the the time has passed. If seconds is zero, it will
block for a very long time.
StcStreamblockException raised on errors. True returned on sucess.
'''
# GTL is this needed?
self._session.stc.apply()
generator = self._session.stc.get(self._port_handle, 'children-generator') # ugh. just ugh.
# stop to get to known state
log.info('Stopping generator to get to known state.')
self._session.perform('GeneratorStop', generatorlist=generator)
# do ARP
log.info('Doing ARP to resolve gateway addresses.')
self._session.perform('ArpNDStart', handlelist=self._handle)
status = self._session.perform('ArpNDVerifyResolved', handlelist=self._handle)
if not status:
raise StcStreamblockException('Error when getting ARP response status.')
if 'PassFailState' not in status or status['PassFailState'] != 'PASSED':
raise StcStreamblockException('ARP failed. Status: {}'.format(status))
log.info('Starting streamblock {}'.format(self._handle))
status = self._session.perform('StreamBlockStart', streamblocklist=self._handle)
def stop_traffic(self):
log.info('Stopping streamblock {}'.format(self._handle))
status = self._session.perform('StreamBlockStop', streamblocklist=self._handle)
return True