def get_port_counter_group(self, unit1, module1, port_number1, unit2, module2, port_number2, counter_group=None): """Get a group of counter values :param unit: the unit (generator) number as a string to be selected :param module: the module (network card) number as a string to be selected :param port_number: the port number as a string to be selected :param counter_group: the name of the group of counters """ description = [] counter_value1 = [] counter_value2 = [] self.select1 = port.select(unit1, module1, port_number1) self.send_msg(self.select1) try: self.messages1 = port.read_group(counter_group, self.anritsu_type) except: self.disconnect() raise for message, desc in sorted(self.messages1.iteritems()): self.socket.send(message) try: data = self.socket.recv(1024) except socket.timeout: raise error.AnritsuTimeout(message) datasplit = str.split(data, ',') description.append(desc) counter_value1.append(datasplit[1]) self.select2 = port.select(unit2, module2, port_number2) self.send_msg(self.select2) try: self.messages2 = port.read_group(counter_group, self.anritsu_type) except: self.disconnect() raise for message, desc in sorted(self.messages2.iteritems()): self.socket.send(message) try: data = self.socket.recv(1024) except socket.timeout: raise error.AnritsuTimeout(message) datasplit = str.split(data, ',') counter_value2.append(datasplit[1]) self.table = texttable.Texttable() self.table.set_cols_dtype(['i', 'i', 'i']) self.table.header(['Counter', 'Int '+ unit1 +'/'+ module1 +'/'+ port_number1, 'Int '+ unit2 +'/'+ module2 +'/'+ port_number2]) for teller, i in enumerate(description): self.table.add_row([description[teller], counter_value1[teller], counter_value2[teller]]) self.table.add_row(['Counter', 'Int '+ unit1 +'/'+ module1 +'/'+ port_number1, 'Int '+ unit2 +'/'+ module2 +'/'+ port_number2]) print(self.table.draw())
def get_port_counter(self, unit, module, port_number, counter_name): """Get a port counter value :param unit: the unit (generator) number as a string to be selected :param module: the module (network card) number as a string to be selected :param port_number: the port number as a string to be selected :param counter_name: the counter that needs to be checked """ self.select = port.select(unit, module, port_number) self.send_msg(self.select) self.counter = port.read(counter_name) data = self.send_recv_msg(self.counter) datasplit = str.split(data, ',') counter_value = datasplit[1] print('requested counter field = ' + counter_value) return int(counter_value)
def test_port_counter(self, unit, module, port_number, counter_name, val1, val2): """Get the port counter values and test if its between the expected range :param unit: the unit (generator) number as a string to be selected :param module: the module (network card) number as a string to be selected :param port_number: the port number as a string to be selected :param counter_name: the counter that needs to be checked :param val1: the value where the range starts :param val2: the value where the range ends """ self.select = port.select(unit, module, port_number) self.send_msg(self.select) self.counter = port.read(counter_name) data = self.send_recv_msg(self.counter) datasplit = str.split(data, ',') counter_value = datasplit[1] if int(counter_value) < val1 or int(counter_value) > val2: print('out of range, result = ' + counter_value) return False else: #print('in range, requested counter field = ' + counter_value) return True