def queueStats(s, deviceInterface, numberOfTimesTransmit, argv): filename = "./logs/" + argv[1] + ".log" file = open(filename, "w+") delay = decimal.Decimal(latency_SampleRate) / decimal.Decimal(1000) sustainedPorts = int(sys.argv[4]) print "delay:" + str(delay) start_time = time.time() print "sending Queue", print "for device %s " % argv[1] #for i in range (0,numberOfTimesTransmit): g = timeStamp() while (1): elapsed_time = time.time() - start_time if elapsed_time >= 300: print "sending Burst for %s at %s\n\n\n" % ( argv[1], datetime.datetime.now()) packet = analytics_pb2.AnRecord() packet.timestamp = timeStamp() for interfaceNumber in trueInterfaces(argv): interfaceName = deviceInterface + str(interfaceNumber) #print interfaceName interfaceX = packet.interface.add() interfaceX.name = interfaceName interfaceX.stats.queue_stats.queue_depth = random_QueueDepth( interfaceNumber) start_time = time.time() #set time to current for next 15 mins #print "Queue send= %s" % packet.timestamp else: T1 = timeStamp() #sending only for one interface every 10 milliseconds packet = analytics_pb2.AnRecord() packet.timestamp = timeStamp() for interfaceNumber in range(startInterface, sustainedPorts): random_interfaceNumber = interfaceNumber #int(random.randrange(startInterface, numberOfInterfaces) ) interfaceName = deviceInterface + str(random_interfaceNumber) interfaceX = packet.interface.add() interfaceX.name = interfaceName interfaceX.stats.queue_stats.queue_depth = random_QueueDepth( random_interfaceNumber) s = sendPacket(s, packet, interfaceX.name, argv) T2 = int(timeStamp()) timeTaken = int((T2 - T1) / 1000) diff = int((T2 - g) / 1000) g = T2 time.sleep(delay) file.write( "current packet sending at= %s, Last packet send %s milliseconds ago for interface= %s total time taken to build packet %s \n" % (T2, diff, interfaceName, timeTaken))
def deviceInfo(s, deviceName, deviceSeriaNumber, model, argv): delay = 1 print "sending device info" packet = analytics_pb2.AnRecord() packet.system.name = argv[1] #packet.timestamp=timeStamp() info = packet.system.information info.boot_time = 1398358901 info.model_info = model info.serial_no = deviceSeriaNumber interfaceList = [] for interfaceNumber in trueInterfaces(argv): interfaceList.append("xe-0/0/" + str(interfaceNumber)) packet.system.information.interface_list.extend(interfaceList) info.max_ports = 104 status = packet.system.status status.queue_status.status = 1 status.queue_status.poll_interval = latency_SampleRate status.queue_status.lt_high = 10000000 status.queue_status.lt_low = 100000 status.traffic_status.status = 1 status.traffic_status.poll_interval = traffic_SampleRate sendPacket(s, packet, packet.system.name, argv) time.sleep(delay) print "sending data for interfaces" index = 1 for interface in interfaceList: interfaceInfo(s, deviceName, interface, index, model, argv) index = index + 1
def receive_record(db, conn): data = conn.recv(HEADER_SIZE) if not data: print 'Connection closed' return False length = ord(data[0]) + (ord(data[1]) << 8) + (ord(data[2]) << 16) + ( ord(data[3]) << 24) version = ord(data[4]) if version != VERSION: print 'Wrong version ', version return False data = conn.recv(length) if not data: print 'Connection closed' return False record = analytics_pb2.AnRecord() record.ParseFromString(data) process_record(db, record) return True
def interfaceInfo(s, deviceName, interface, index, model, argv): portNumber = interface.split('/') packet = analytics_pb2.AnRecord() #packet.timestamp=timeStamp() infoInterface = packet.interface.add() infoInterface.name = argv[1] + ":" + str(interface) '''for name in packet.interface: print name''' info = infoInterface.information info.snmp_index = 500 + index info.index = 644 + index info.slot = 0 info.port = int(portNumber[-1]) info.media_type = 2 info.capability = 43072 info.porttype = 184 pStatus = infoInterface.status.link pStatus.speed = 10000000000 pStatus.duplex = 2 pStatus.mtu = 1514 pStatus.state = True pStatus.auto_negotiation = True sendPacket(s, packet, packet.system.name, argv)
def trafficStats(s, deviceInterface, numberOfTimeTransmit, argv): time.sleep( 30 ) # this sleep is for setting the delay between the queue process so that device info could be send in advance delay = traffic_SampleRate last_traffic = 100000000 print "sending Traffic", print "for device %s " % argv[1] #for i in range (0,numberOfTimesTransmit): while (1): packet = analytics_pb2.AnRecord() traffic = average_Traffic(last_traffic) last_traffic = traffic if last_traffic >= 100000000000: last_traffic = 1000000 #for interfaceNumber in range(startInterface,numberOfInterfaces): for interfaceNumber in trueInterfaces(argv): trafficInterface = packet.interface.add() interfaceName = deviceInterface + str(interfaceNumber) trafficInterface.name = interfaceName #time Stamp #print packet.timestamp packet.timestamp = timeStamp() Traffic_Stats = trafficInterface.stats.traffic_stats Traffic_Stats.rxpkt = int( random.randrange(3000000, 621286497, 1000000)) Traffic_Stats.rxucpkt = Traffic_Stats.rxpkt Traffic_Stats.rxpps = int(random.randrange(5, 200, 5)) #Traffic_Stats.rxmcpkt=traffic #Traffic_Stats.rxbcpkt= Traffic_Stats.rxbyte = int( random.randrange(50000000000, 99000000000, 1234567891)) Traffic_Stats.rxbps = int(random.randrange(11264, 35000, 5345)) Traffic_Stats.rxcrcerr = int(random.randrange(40, 345, 9)) Traffic_Stats.rxdroppkt = int( random.randrange(3400000, 4999999, 100000)) Traffic_Stats.txpkt = int(random.randrange(2000000, 3392364, 19236)) Traffic_Stats.txucpkt = Traffic_Stats.txpkt #Traffic_Stats.txmcpkt=traffic #Traffic_Stats.txbcpkt=traffic Traffic_Stats.txpps = int(random.randrange(5, 200, 5)) Traffic_Stats.txbyte = int( random.randrange(50000000000, 59000000000, 1234567891)) Traffic_Stats.txbps = int(random.randrange(11264, 350000, 9345)) #Traffic_Stats.txcrcerr=traffic Traffic_Stats.txdroppkt = int( random.randrange(40000000, 55263947, 100000)) print "traffic send %s" % interfaceName s = sendPacket(s, packet, trafficInterface.name, argv) '''sendTraffic=True while (sendTraffic): try: lock.acquire() #print "send traffic" s=sendPacket(s, packet, trafficInterface.name, argv) sendTraffic=False lock.release() except IOError: print "socket used for sending queue data" time.sleep(0.6)''' time.sleep(delay)