Exemplo n.º 1
0
	def arp(self, arp_type, sender_mac, sender_ip, target_mac, target_ip):
		"""Creates messages to set the ARP protocol

		:param arp_type:  set the type of ARP as defined in RFC 826 and RFC 903 can select out of the following set: 'ARP request', 'ARP reply', 'RARP request', 'RARP reply'
		:param sender_mac: set the sender's MAC address. (e.g. 00-DE-BB-00-00-00)
		:param sender_ip: set the sender's IP address. (e.g. 192.168.1.3)
		:param target_mac: set the target's MAC address. (e.g. 00-DE-BB-00-00-00)
		:param target_ip: set the target's IP address. (e.g. 192.168.1.3)

		"""
		input_validator.string_set(['ARP request', 'ARP reply', 'RARP request', 'RARP reply'], arp_type)
		self.arp_type_translator = {}
		self.arp_type_translator['ARP request'] = '1'
		self.arp_type_translator['ARP reply'] = '2'
		self.arp_type_translator['RARP request'] = '3'
		self.arp_type_translator['RARP reply'] = '4'
		self.sender_mac_address_hexed = convert_calc.MactoHex(sender_mac)
		self.target_mac_address_hexed = convert_calc.MactoHex(target_mac)
		self.sender_ip_address = convert_calc.IPtoHex(sender_ip)
		self.target_ip_address = convert_calc.IPtoHex(target_ip)
		self.sender_ip_address_hexed = self.sender_ip_address[0]
		self.target_ip_address_hexed = self.target_ip_address[0]
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:ARP:OPERation ' + str(self.arp_type_translator.get(arp_type)) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:ARP:SMADdress ' + str(self.sender_mac_address_hexed) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:ARP:SIADdress ' + str(self.sender_ip_address_hexed) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:ARP:TIADdress ' + str(self.target_ip_address_hexed) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:ARP:TMADdress ' + str(self.target_mac_address_hexed) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:ARP:OPERation?\n'] = str(self.arp_type_translator.get(arp_type) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:ARP:SMADdress?\n'] = str(self.sender_mac_address_hexed) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:ARP:SIADdress?\n'] = str(self.sender_ip_address_hexed) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:ARP:TIADdress?\n'] = str(self.target_ip_address_hexed) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:ARP:TMADdress?\n'] = str(self.target_mac_address_hexed) + '\n'
Exemplo n.º 2
0
	def distribution(self, stream_distribution_type, jump_to_id=None, count=None):
		"""Creates messages to define the type of distribution of the stream.
	
		:param stream_distribution_type: can choose from 'CONT', 'CONT_BURST', 'STOP', 'NEXT', 'JUMP', 'JUMP_COUNT', 'JUMP_STOP'.
		:param jump_to_id: if the distribution type is 'JUMP', 'JUMP_COUNT', 'JUMP_STOP', this parameter represents to what stream ID to JUMP to. Expects to be a number between 1 and 256 (requirement: the stream id must be already set on the Anritsu)
		:param count: if the distribution type is 'JUMP_COUNT', 'JUMP_STOP'. This parameter sets the loop count, which is the amount of jumps, before this stream stops. Expects to be a number between 1 and 256.
	
		"""
		# First validate the user input
		input_validator.string_set(['CONT', 'CONT_BURST', 'STOP', 'NEXT', 'JUMP', 'JUMP_COUNT', 'JUMP_STOP'], stream_distribution_type)
		# Append the associated command message to the self.commands list, to set a variable on the Anritsu
		self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:DISTribution ' + str(stream_distribution_type) + '\n')
		# Write the corresponding query message to the self.stream_queries dictionary as a key and the input as it value.
		# Which is required to test a variable on the Anritsu with the users input value.
		self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:DISTribution?\n'] = str(stream_distribution_type) + '\n'
		# Expect extra parameters when a certain subset of the first argument is set and append the required command and query messages.
		if stream_distribution_type == 'JUMP':
			input_validator.value_minimum_maximum(1, 256, jump_to_id)
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:JTID ' + str(jump_to_id) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:JTID?\n'] = str(jump_to_id) + '\n'
		elif stream_distribution_type == 'JUMP_COUNT' or stream_distribution_type == 'JUMP_STOP':
			input_validator.value_minimum_maximum(1, 256, jump_to_id)
			input_validator.value_minimum_maximum(1, 16000000, count)
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:JTID ' + str(jump_to_id) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:COUNt ' + str(count) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:JTID?\n'] = str(jump_to_id) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:COUNt?\n'] = str(count) + '\n'
Exemplo n.º 3
0
	def test_frame(self, test_type, length_or_offset=None, flow_id=None):
		"""Adds a test frame in the frame its data field

		:param test_type: the type of test used, can select out of the following set: 'PRBS', 'flow'.
		:param length_or_offset: the length in bytes of a PRBS test frame and the offset in bytes of a flow test frame.
		:param flow_id: when a flow test frame is selected, this is the ID.

		"""
		input_validator.string_set(['PRBS', 'FLOW'], test_type)
		if test_type == 'PRBS':
			input_validator.value_minimum_maximum(46, 65517, length_or_offset)
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:ENABle 1\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TYPE TEST_FRAME\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:TYPE '  + str(test_type) + '\n')
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:ENABle?\n'] = '1\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:ITFRame?\n'] = '1\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TYPE?\n'] = 'TEST_FRAME\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:TYPE?\n'] = str(test_type) + '\n'
			if length_or_offset != None:
				self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:LENGth '  + str(length_or_offset) + '\n')
				self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:LENGth?\n'] = str(length_or_offset) + '\n'
		elif test_type == 'FLOW':
			input_validator.value_minimum_maximum(28, 65499, length_or_offset)
			input_validator.value_minimum_maximum(0, 65535, flow_id)
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:ENABle 1\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TYPE TEST_FRAME\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:TYPE FLOW_ID\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:FID ' + str(flow_id) + '\n')
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:ENABle?\n'] = '1\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TYPE?\n'] = 'TEST_FRAME\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:TYPE?\n'] = 'FLOW_ID\n'
			self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:TFRame:FID?\n'] = str(flow_id) + '\n'
			if length_or_offset != None:
				self.commands.append(':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:OFFSet ' + str(length_or_offset) + '\n')
				self.frame_queries[':TSTReam:TABLe:ITEM:FRAMe:DFIeld1:OFFSet?\n'] = str(length_or_offset) + '\n'
Exemplo n.º 4
0
	def frame_size(self, frame_size_type, frame_size_value=None, frame_size_maximum=None):
		"""Creates messages to define what frame size type is needed. 
	
		:param frame_size_type: the type of frame size, which can be 'AUTO', 'FIXED', 'INCREMENT', 'RANDOM'
		:param frame_size_value param: if the frame size type is 'AUTO', this value is ignored. If 'FIXED' it is the frame size. If 'INCREMENT' or 'RANDOM', it is the minimum frame size.
		:param frame_size_maximum: ignored with frame size type 'AUTO' and 'FIXED'. If it is 'INCREMENT' or 'RANDOM' it is the maximum frame size.
	
		"""
		input_validator.string_set(['AUTO', 'FIXED', 'INCREMENT', 'RANDOM'], frame_size_type)
		if frame_size_type == 'AUTO':
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:TYPE ' + str(frame_size_type) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:TYPE?\n'] = str(frame_size_type) + '\n'
		elif frame_size_type == 'FIXED':
			input_validator.value_minimum_maximum(8, 65280, frame_size_value)
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:TYPE ' + str(frame_size_type) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:VALue ' + str(frame_size_value) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:TYPE?\n'] = str(frame_size_type) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:VALue?\n'] = str(frame_size_value) + '\n'
		elif frame_size_type == 'INCREMENT':
			input_validator.value_minimum_maximum(8, 65280, frame_size_value)
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:TYPE ' + str(frame_size_type) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:MINimum ' + str(frame_size_value) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:MAXimum ' + str(frame_size_maximum) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:TYPE?\n'] = str(frame_size_type) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:MINimum?\n'] = str(frame_size_value) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:MAXimum?\n'] = str(frame_size_maximum) + '\n'
		elif frame_size_type == 'RANDOM':
			input_validator.value_minimum_maximum(8, 65280, frame_size_value)
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:TYPE ' + str(frame_size_type) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:MINimum ' + str(frame_size_value) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:FSIZe:MAXimum ' + str(frame_size_maximum) + '\n')
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:TYPE?\n'] = str(frame_size_type) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:MINimum?\n'] = str(frame_size_value) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:FSIZe:MAXimum?\n'] = str(frame_size_maximum) + '\n'
Exemplo n.º 5
0
	def inter_frame_gap(self, inter_frame_gap_type, inter_frame_gap_value, inter_frame_gap_maximum=None):
		"""Creates messages to define the Inter Frame Gap (IFG).
	
		:param inter_frame_gap_type: the type of IFG, which can be 'FIXED' or 'RANDOM'. 
		:param inter_frame_gap_value: if the IFG type is 'FIXED', this will be the fixed IFG in nanosecond (ns). If its 'RANDOM', the keyword represents the minimum time in ns.
		:param inter_frame_gap_maximum: if the IFG type is 'RANDOM', this keyword is the maximum time in ns.
	
		"""
		# First validate the user input
		input_validator.string_set(['FIXED', 'RANDOM'], inter_frame_gap_type)
		if inter_frame_gap_type == 'FIXED':
			input_validator.value_minimum_maximum(1, 1200000000000, inter_frame_gap_value)
			# Append the associated command message to the self.commands list, to set a variable on the Anritsu
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:TYPE ' + str(inter_frame_gap_type) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:VALue ' + str(inter_frame_gap_value) + '\n')
			# Write the corresponding query message to the self.stream_queries dictionary as a key and the input as it value.
			# Which is required to test a variable on the Anritsu with the users input value.
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:TYPE?\n'] = str(inter_frame_gap_type) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:VALue?\n'] = str(inter_frame_gap_value) + '\n'
		if inter_frame_gap_type == 'RANDOM':
			input_validator.value_minimum_maximum(1, 1200000000000, inter_frame_gap_value)
			input_validator.value_minimum_maximum(1, 1200000000000, inter_frame_gap_maximum)
			# Append the associated command message to the self.commands list, to set a variable on the Anritsu
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:TYPE ' + str(inter_frame_gap_type) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:MINimum ' + str(inter_frame_gap_value) + '\n')
			self.commands.append(':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:MAXimum ' + str(inter_frame_gap_maximum) + '\n')
			# Write the corresponding query message to the self.stream_queries dictionary as a key and the input as it value.
			# Which is required to test a variable on the Anritsu with the users input value.
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:TYPE?\n'] = str(inter_frame_gap_type) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:VALue?\n'] = str(inter_frame_gap_value) + '\n'
			self.stream_queries[':TSTReam:TABLe:ITEM:CONTrol:GAP:IFG:MAXimum?\n'] = str(inter_frame_gap_maximum) + '\n'
Exemplo n.º 6
0
	def ipv4_error(self, error_type):
		"""Insert an IPv4 error in a stream.

		:param error_type: what type of IPv4 error, can select out of the following set: 'CHECKSUM'.

		"""
		input_validator.string_set(['CHECKSUM'], error_type)
		self.commands.append(':TSTReam:TABLe:ITEM:ERRor:IP:TYPE ' + str(error_type) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:ERRor:IP:TYPE?\n'] = str(error_type) + '\n'
Exemplo n.º 7
0
	def ethernet_error(self, error_type):
		"""Insert an ethernet error in a stream.

		:param error_type: what type of ethernet error, can select out of the following set: 'FCS', 'UNDERSIZE', 'OVERSIZE', 'OVERSIZE_FCS', 'PRBS_BIT'.

		"""
		input_validator.string_set(['FCS', 'UNDERSIZE', 'OVERSIZE', 'OVERSIZE_FCS', 'PRBS_BIT'], error_type)
		self.commands.append(':TSTReam:TABLe:ITEM:ERRor:ETHernet:TYPE ' + str(error_type) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:ERRor:ETHernet:TYPE?\n'] = str(error_type) + '\n'
Exemplo n.º 8
0
	def protocol(self, stream_protocol):
		"""Creates messages to define the protocol in the stream. 

		:param protocol: the protocol used, can select out of the following set: 'NONE', 'ARP', 'IPV4', 'IGMP', 'IGAP', 'ICMP', 'TCP', 'UDP', 'RIP', 'DHCP', 'IPV6', 'ICMP6', 'TCP_IPV6', 'UDP_IPV6', 'TUNNEL', 'ICMP6_TUNNEL', 'TCP_TUNNEL', 'UDP_TUNNEL', 'TUNNEL6', 'TCP_TUNNEL6', 'UDP_TUNNEL6', 'IPX', 'IS_IS', 'MAC_CONTROL', 'EHTERNET', 'LEX_CONTROL', 'BPUD', 'LACP'.

		"""
		input_validator.string_set(['NONE', 'ARP', 'IPV4', 'IGMP', 'IGAP', 'ICMP', 'TCP', 'UDP', 'RIP', 'DHCP', 'IPV6', 'ICMP6', 'TCP_IPV6', 'UDP_IPV6', 'TUNNEL', 'ICMP6_TUNNEL', 'TCP_TUNNEL', 'UDP_TUNNEL', 'TUNNEL6', 'TCP_TUNNEL6', 'UDP_TUNNEL6', 'IPX', 'IS_IS', 'MAC_CONTROL', 'EHTERNET', 'LEX_CONTROL', 'BPUD', 'LACP'], stream_protocol)
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:TYPE ' + str(stream_protocol) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:TYPE?\n'] = str(stream_protocol) + '\n'
Exemplo n.º 9
0
	def ipv6_destination_address(self, ipv6_destination_address, ipv6_destination_address_type='STATIC'):
		"""Creates messages to define the packets destination IPv6 address. 

		:param ipv6_destination_address: destination IPv6 address e.g. '1:2:3:4:5:6:7:8'
		:param ipv6_destination_address_type: destination address type,  can select out of the following set: 'GATEWAY', 'STATIC', 'INCREMENT', 'DECREMENT', 'RANDOM'

		"""
		input_validator.string_set(['GATEWAY', 'STATIC', 'INCREMENT', 'DECREMENT', 'RANDOM'], ipv6_destination_address_type)
		ipv6_address_and_mask = convert_calc.IPtoHex(ipv6_destination_address)
		hexed_ipv6_destination_address = ipv6_address_and_mask[0] 
		hexed_ipv6_destination_mask = ipv6_address_and_mask[1]
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:TYPE ' + str(ipv6_destination_address_type) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:VALue ' + str(hexed_ipv6_destination_address) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:MASK ' + str(hexed_ipv6_destination_mask) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:TYPE?\n'] = str(ipv6_destination_address_type) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:VALue?\n'] = str(hexed_ipv6_destination_address) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:DA:MASK?\n'] = str(hexed_ipv6_destination_mask) + '\n'
Exemplo n.º 10
0
	def ipv6_source_address(self, ipv6_source_address, ipv6_source_address_type='STATIC'):
		"""Creates messages to define the packets source IPv6 address. 

		:param ipv6_source_address: source IPv6 address e.g. '1:2:3:4:5:6:7:8/64'
		:param ipv6_source_address_type: source address type,  can select out of the following set: 'GATEWAY', 'STATIC', 'INCREMENT', 'DECREMENT', 'RANDOM'

		"""
		input_validator.string_set(['GATEWAY', 'STATIC', 'INCREMENT', 'DECREMENT', 'RANDOM'], ipv6_source_address_type)
		# First convert and validate the users input IPv6 address
		ipv6_address_and_mask = convert_calc.IPtoHex(ipv6_source_address)
		hexed_ipv6_source_address = ipv6_address_and_mask[0]
		hexed_ipv6_source_mask = ipv6_address_and_mask[1]
		# Then append the commands and the corresponding queries, to set and test a variable on the Anritsu
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:TYPE ' + str(ipv6_source_address_type) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:VALue ' + str(hexed_ipv6_source_address) + '\n')
		self.commands.append(':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:MASK ' + str(hexed_ipv6_source_mask) + '\n')
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:TYPE?\n'] = str(ipv6_source_address_type) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:VALue?\n'] = str(hexed_ipv6_source_address) + '\n'
		self.frame_queries[':TSTReam:TABLe:ITEM:PROTocol:IPv6:SA:MASK?\n'] = str(hexed_ipv6_source_mask) + '\n'
Exemplo n.º 11
0
	def __init__(self, address, anritsu_type):
		"""Connect to a given analyzer on port 5001, save the given expected Anritsu type. Additionally it waits and cleans old query replies from the Anritsu. This process follows these steps: we start by expecting a reply within 5 seconds. If no reply is received, we assume old queries replies are cleaned. This cleaning process is repeated two times, just to be sure.
	
		:param address: host name or IP address
	
		"""
		self.socket = socket.create_connection((address, 5001))
		self.anritsu_type = str.lower(anritsu_type)
		input_validator.string_set(['md1230b', 'md1260a'], anritsu_type)
		# Cleaning old query replies 
		self.try_count = 2
		while self.try_count != 0:
			try:
				self.socket.settimeout(5)
				self.socket.recv(1024)
			except socket.timeout:
				self.try_count = self.try_count - 1
			else:
				self.try_count = self.try_count - 1
				print('Received old message, retrying ')
		# Setting socket timeout back to 20 seconds
		self.socket.settimeout(20)