def __init__(self, start_time, src_ip, dst_ip, flow_size, src_port=-1, dst_port=-1, duration=0.0): #set src_port and dst_port to -1 if not available self.start_time = TimeUtils.time_convert(start_time) self.end_time = self.start_time + TimeUtils.time_delta_convert(duration) self.src_ip = src_ip self.src_port = src_port self.dst_ip = dst_ip self.dst_port = dst_port self.size = flow_size
def add_packet(self, packet, duration=0.0): """ add a new packet to flow :param packet: an object of Packet :param duration: new packet's duration :return: None """ assert isinstance(packet, Packet), 'Wrong argument when adding a packet to flow' assert packet.src_port == self.src_port, 'src_port number should be the same' self.start_time = self.start_time if self.start_time < packet.packet_time else packet.packet_time self.end_time = TimeUtils.time_convert(packet.packet_time) + TimeUtils.time_delta_convert(duration) self.size += packet.packet_size self.packet_num += 1
def add_packet(self, packet, duration=0.0): """ add a new packet to flow :param packet: an object of Packet :param duration: new packet's duration :return: None """ assert isinstance( packet, Packet), 'Wrong argument when adding a packet to flow' assert packet.src_port == self.src_port, 'src_port number should be the same' self.start_time = self.start_time if self.start_time < packet.packet_time else packet.packet_time self.end_time = TimeUtils.time_convert( packet.packet_time) + TimeUtils.time_delta_convert(duration) self.size += packet.packet_size self.packet_num += 1
def __init__(self, start_time, src_ip, dst_ip, flow_size, src_port=-1, dst_port=-1, duration=0.0): #set src_port and dst_port to -1 if not available self.start_time = TimeUtils.time_convert(start_time) self.end_time = self.start_time + TimeUtils.time_delta_convert( duration) self.src_ip = src_ip self.src_port = src_port self.dst_ip = dst_ip self.dst_port = dst_port self.size = flow_size
def packet_coflow_str(packet, coflow_id, app_id): packet_str = [ TimeUtils.time_offset(packet.packet_time), ip2int(packet.src_ip), packet.src_port, ip2int(packet.dst_ip), packet.dst_port, app_id_to_int(app_id), coflow_id, packet.packet_size ] return " ".join(map(str, packet_str))
def from_log_line(cls, src_ip, log_line): fields = log_line.strip().split(' ') app_id = fields[0].split('/')[5].strip() start_time_str = fields[0].split(":")[1] + " " + fields[1] start_time = TimeUtils.time_convert(start_time_str) [stage_id, blocks, size, dst] = map(lambda x: x.split("=")[1], fields[5:]) dst_name, dst_port = dst.split(':') dst_ip = host2ip(dst_name) size = int(size) blocks = int(blocks) return cls(start_time, stage_id, blocks, size, dst_ip, dst_port, src_ip, app_id)
def parse_pcap(pcap_file, filters=''): pcap_obj = pcap.pcap(pcap_file) if filters != '': pcap_obj.setfilter(filters) for ts, pkt in pcap_obj: eth = dpkt.ethernet.Ethernet(pkt) tos = eth.ip.tos shuffle_id = tos / 4 - 1 src_ip = socket.inet_ntoa(eth.ip.src) src_port = eth.ip.tcp.sport dst_ip = socket.inet_ntoa(eth.ip.dst) dst_port = eth.ip.tcp.dport size = eth.ip.len yield Packet(shuffle_id, TimeUtils.time_convert(ts), src_ip, src_port, dst_ip, dst_port, size)
def from_line_str(cls, flow_line): """ get packet object from a line in captured file. :param flow_line: a line in captured file. :return: a packet object """ try: [shuffle_code, packet_time, src_ip, src_port, dst_ip, dst_port, packet_size] = flow_line.split("\t") stage_id = str((int(shuffle_code) / 4) - 1) packet_time = TimeUtils.time_convert(packet_time) packet_size = int(packet_size) except ValueError: return None else: return cls(stage_id, packet_time, src_ip, src_port, dst_ip, dst_port, packet_size)
def packet_coflow_str(packet, coflow_id, app_id): packet_str = [TimeUtils.time_offset(packet.packet_time), ip2int(packet.src_ip), packet.src_port, ip2int(packet.dst_ip), packet.dst_port, app_id_to_int(app_id), coflow_id, packet.packet_size] return " ".join(map(str, packet_str))
def __str__(self): return "%s %s %s %s:%s %d" % \ (TimeUtils.time_to_string(self.start_time), self.stage_id, self.src_ip, self.dst_ip, self.dst_port, self.size)
def __str__(self): return "%s\t%s\t%s:%s->%s:%s\t%d\t%d" % \ (TimeUtils.time_to_string(self.start_time), self.duration.total_seconds(), self.src_ip, self.src_port, self.dst_ip, self.dst_port, self.size, self.retransmit_bytes)
def __init__(self): self.coflows = {} self.threshold1 = TimeUtils.time_delta_convert(1)
def __str__(self): return "Coflow " + str(self.coflow_id) + ":\n" + TimeUtils.time_to_string(self.start_time) + " " + \ str((self.end_time - self.start_time).total_seconds()) + '\n' + "Logical Flows:\n" + \ "\n".join(map(str, self.logical_flows.values())) + "\n" + "Real Flows:\n" + \ "\n".join(map(str, self.realistic_flows.values()))
def __str__(self): return str(self.stage_id) + " " + TimeUtils.time_to_string(self.packet_time) + " "\ + self.src_ip + ":" + self.src_port + " " + self.dst_ip + ":" + self.dst_port\ + " " + str(self.packet_size)
from packet import Packet from flow import LogicalFlow from flow import RealisticFlow from utils.time import TimeUtils START_TIME_THRESHOLD = TimeUtils.time_delta_convert(1.0) END_TIME_THRESHOLD = TimeUtils.time_delta_convert(10.0) class Coflow(object): """ a coflow abstraction """ def __init__(self, logical_flow): assert isinstance( logical_flow, LogicalFlow ), 'Wrong argument when initializing a coflow with a logical_flow' self.start_time = logical_flow.start_time self.end_time = self.start_time self.coflow_id = logical_flow.stage_id self.logical_flows = { logical_flow.generate_logical_flow_id(): logical_flow } self.realistic_flows = {} def __str__(self): return "Coflow " + str(self.coflow_id) + ":\n" + TimeUtils.time_to_string(self.start_time) + " " + \ str((self.end_time - self.start_time).total_seconds()) + '\n' + "Logical Flows:\n" + \ "\n".join(map(str, self.logical_flows.values())) + "\n" + "Real Flows:\n" + \ "\n".join(map(str, self.realistic_flows.values()))
from packet import Packet from flow import LogicalFlow from flow import RealisticFlow from utils.time import TimeUtils START_TIME_THRESHOLD = TimeUtils.time_delta_convert(1.0) END_TIME_THRESHOLD = TimeUtils.time_delta_convert(10.0) class Coflow(object): """ a coflow abstraction """ def __init__(self, logical_flow): assert isinstance(logical_flow, LogicalFlow), 'Wrong argument when initializing a coflow with a logical_flow' self.start_time = logical_flow.start_time self.end_time = self.start_time self.coflow_id = logical_flow.stage_id self.logical_flows = {logical_flow.generate_logical_flow_id(): logical_flow} self.realistic_flows = {} def __str__(self): return "Coflow " + str(self.coflow_id) + ":\n" + TimeUtils.time_to_string(self.start_time) + " " + \ str((self.end_time - self.start_time).total_seconds()) + '\n' + "Logical Flows:\n" + \ "\n".join(map(str, self.logical_flows.values())) + "\n" + "Real Flows:\n" + \ "\n".join(map(str, self.realistic_flows.values())) @property def duration(self):