示例#1
0
	def __parse(self):
		print "Parsing file..."
		parser = FileParser()
		self.lines = parser.parse(file)

		# contains distinct flows, opened with a SYN
		self.flows = {}

		for line in self.lines:
			line = line.strip()
			tokens = line.split(' ')
			tokens = self.__clean(tokens)
			if '.' not in tokens[1]:
				continue

			key = self.__get_key(tokens)

			if "SYN" in line:
				self.flows[key] = []
				continue

			if "Len=0" in line:
				continue

			time = float(tokens[1])
			length = 0
			for token in tokens:
				if "Len=" in token:
					length = int(token.split('=')[1])
					break

			self.flows[key].append((time, length))
示例#2
0
    def __parse__(self):
        parser = FileParser()
        packets = False
        acks = False
        drops = False
        do_nothing = False
        for line in parser.parse(self.input):
            if len(line) == 0:
                continue

            if "skip" in line:
                do_nothing = True

            if line.startswith("\"packets"):
                packets = True
                do_nothing = False
                continue

            if line.startswith("\"acks"):
                acks = True
                drops = False
                do_nothing = False
                continue

            if line.startswith("\"drops"):
                drops = True
                do_nothing = False
                continue

            if do_nothing:
                continue

            if packets and not acks:
                if drops:
                    self.packet_drops.append(line)
                else:
                    self.packets.append(line)

            if acks:
                if drops:
                    self.ack_drops.append(line)
                else:
                    self.acks.append(line)
示例#3
0
	def __parse__(self):
		parser = FileParser()
		packets = False
		acks = False
		drops = False
		do_nothing = False
		for line in parser.parse(self.input):
			if len(line) == 0:
				continue

			if "skip" in line:
				do_nothing = True
				
			if line.startswith("\"packets"):
				packets = True
				do_nothing = False
				continue
				
			if line.startswith("\"acks"):
				acks = True
				drops = False
				do_nothing = False
				continue

			if line.startswith("\"drops"):
				drops = True
				do_nothing = False
				continue

			if do_nothing:
				continue

			if packets and not acks:
				if drops:
					self.packet_drops.append(line)
				else:
					self.packets.append(line)
			
			if acks:
				if drops:
					self.ack_drops.append(line)
				else:
					self.acks.append(line)
示例#4
0
文件: display.py 项目: chazu/jinxes
class TartanDisplay(object):
    def __init__(self, app, spec, driver='gl'):
        self.app = app
        self.spec = spec
        self.widgets = []
        self.focus_order = None
        self.parser = FileParser(self.app)
        self.widgets = self.parser.parse(self.spec["widgets"])
        self.canvas = Canvas(self.spec["app"]["width"],
                             self.spec["app"]["height"])
        self.display = Display(self.canvas)
        self.display.set_driver(driver)

        if len(self.widgets) > 0:
            self.focused_widget = self.widgets[0]
        self.build_focus_order()

    def mark_dirty(self):
        self.dirty = True

    def mark_clean(self):
        self.dirty = False

    def build_focus_order(self):
        self.focus_order = self.widgets

    def refresh(self):
        self.canvas.clear()
        self.build_display()
        self.display.refresh()

    def blit(self, widget):
        self.canvas.blit(widget.anchor[0], widget.anchor[1], widget.canvas)

    def build_display(self):
        self.canvas.clear()
        for widget in self.widgets:
            widget.draw()
            self.blit(widget)
示例#5
0
    def __parse(self):
        parser = FileParser()

        s = set()

        packet_numbers = {}
        sequence_numbers = {}

        start = False

        for line in parser.parse(self.input):
            array = line.split()
            if len(array) == 6:
                # header
                continue

            if "Len=0" not in line:
                start = True

            if not start:
                continue

            if "FIN" in line:
                break

            is_ack = ("ACK" in line) and ("Len=0" in line)
            is_data = ("Len=0" not in line) or ("SYN" in line) or ("FIN"
                                                                   in line)

            packet_number = -1
            time = float(array[1]) + 1  # add one to be like ns-2

            sequence_number = -1
            length = -1
            ack_number = -1

            for item in array:
                if is_data and "Seq=" in item:
                    sequence_number = int(item.split("=")[1])
                    packet_number = self.__get_packet_number(sequence_number)
                elif is_ack and "Ack=" in item:
                    ack_number = int(item.split("=")[1])
                elif "Len=" in item:
                    length = int(item.split("=")[1])

            if "SYN" in line or "FIN" in line:
                length = 1

            temp = ""

            if packet_number < 10:
                temp = "0"

            tsvl = array[-2]
            tser = array[-1]
            ts = tsvl + tser

            if is_data:
                data = str(time) + " " + "1." + temp + str(packet_number)
                self.packets.append(data)
                packet_key = sequence_number + length
                #				print "Packet key:    ", packet_key
                #				print "Packet number: ", packet_number
                if packet_key not in packet_numbers.keys():
                    packet_numbers[sequence_number + length] = packet_number

            else:
                assert is_ack
                if ts in s:
                    #					print "Ack number: ", ack_number
                    #
                    #					print "Ack packet number: ", packet_numbers[ack_number]

                    temp = ""
                    if packet_numbers[ack_number] < 10:
                        temp = "0"

                    data = str(time) + " " + "1." + temp + str(
                        packet_numbers[ack_number])
                    #					print data
                    self.acks.append(data)

            if length > 1 and sequence_numbers.has_key(
                    sequence_number
            ) and sequence_numbers[sequence_number] != ts:
                # duplicate
                for item in self.packets:
                    num = item.split()[1]
                    num = int(num.split(".")[1])
                    if num == self.__get_packet_number(sequence_number):
                        self.packets.remove(item)
                        self.packet_drops.append(item)

                        break

            s.add(ts)

            if length > 1 and sequence_numbers.has_key(
                    sequence_number
            ) and sequence_numbers[sequence_number] == ts:
                del sequence_numbers[sequence_number]
            else:
                sequence_numbers[sequence_number] = ts
示例#6
0
	def __parse(self):
		parser = FileParser()

		s = set()

		packet_numbers = {}
		sequence_numbers = {}

		start = False;
		
		for line in parser.parse(self.input):
			array = line.split()
			if len(array) == 6:
				# header
				continue

			if "Len=0" not in line:
				start = True

			if not start:
				continue

			if "FIN" in line:
				break;

			is_ack = ("ACK" in line) and ("Len=0" in line)
			is_data = ("Len=0" not in line) or ("SYN" in line) or ("FIN" in line)

			packet_number = -1
			time = float(array[1]) + 1 # add one to be like ns-2

			sequence_number = -1
			length = -1
			ack_number = -1

			for item in array:
				if is_data and "Seq=" in item:
					sequence_number = int(item.split("=")[1])
					packet_number = self.__get_packet_number(sequence_number)
				elif is_ack and "Ack=" in item:
					ack_number = int(item.split("=")[1])
				elif "Len=" in item:
					length = int(item.split("=")[1])

			if "SYN" in line or "FIN" in line:
				length = 1
				
					
			temp = ""
			

			if packet_number < 10:
				temp = "0"

			tsvl = array[-2]
			tser = array[-1]
			ts = tsvl + tser

			if is_data:
				data = str(time) + " " + "1." + temp + str(packet_number)
				self.packets.append(data)
				packet_key = sequence_number + length
#				print "Packet key:    ", packet_key
#				print "Packet number: ", packet_number
				if packet_key not in packet_numbers.keys():
					packet_numbers[sequence_number + length] = packet_number

				
					
			else:
				assert is_ack
				if ts in s:
#					print "Ack number: ", ack_number
#
#					print "Ack packet number: ", packet_numbers[ack_number]

					temp = ""
					if packet_numbers[ack_number] < 10:
						temp = "0"
					
					data = str(time) + " " + "1." + temp + str(packet_numbers[ack_number])
#					print data
					self.acks.append(data)


			


			if length > 1 and sequence_numbers.has_key(sequence_number) and sequence_numbers[sequence_number] != ts:
				# duplicate
				for item in self.packets:					
					num = item.split()[1]
					num = int(num.split(".")[1])
					if num == self.__get_packet_number(sequence_number):
						self.packets.remove(item)
						self.packet_drops.append(item)
						
						break
				

			s.add(ts)


			if length > 1 and sequence_numbers.has_key(sequence_number) and sequence_numbers[sequence_number] == ts:
				del sequence_numbers[sequence_number]
			else:
				sequence_numbers[sequence_number] = ts
示例#7
0
from statemachine import StateMachine
from fileparser import FileParser

input_file = 'SampleStateTransitions.csv'
output_file = 'output/StateMachine'
output_format = 'svg'

# Parse csv file
nodes, transitions = FileParser.parse(input_file)

# Create state machine and render it
state_machine = StateMachine(output_format)
state_machine.add(nodes, transitions)
state_machine.render(output_file)