def display(self, result): if result == [] or result is None: return flow_dict_list = result for flow_dict in flow_dict_list: # Setup time if self._SETUP_TIME in flow_dict: setup_time = int(flow_dict[self._SETUP_TIME]) if setup_time != 0: setup_dt = datetime.datetime.fromtimestamp( setup_time / OpServerUtils.USECS_IN_SEC) setup_dt += datetime.timedelta( microseconds= (setup_time % OpServerUtils.USECS_IN_SEC)) setup_ts = setup_dt.strftime( OpServerUtils.TIME_FORMAT_STR) else: setup_ts = 'Setup Time: NA' else: setup_ts = 'Setup Time: NA' # Teardown time if self._TEARDOWN_TIME in flow_dict: teardown_time = int(flow_dict[ self._TEARDOWN_TIME]) if teardown_time != 0: teardown_dt = datetime.datetime.fromtimestamp( teardown_time / OpServerUtils.USECS_IN_SEC) teardown_dt += datetime.timedelta( microseconds= (teardown_time % OpServerUtils.USECS_IN_SEC)) teardown_ts = teardown_dt.strftime( OpServerUtils.TIME_FORMAT_STR) else: teardown_ts = 'Active' else: teardown_ts = 'Active' # VRouter if self._VROUTER in flow_dict: vrouter = flow_dict[self._VROUTER] else: vrouter = 'VRouter: NA' # Direction if self._DIRECTION in flow_dict: direction = int(flow_dict[self._DIRECTION]) if direction == 1: direction = 'ingress' elif direction == 0: direction = 'egress' else: direction = 'Direction: Invalid' else: direction = 'Direction: NA' # Flow UUID if VizConstants.FLOW_TABLE_UUID in flow_dict: flow_uuid = flow_dict[VizConstants.FLOW_TABLE_UUID] else: flow_uuid = 'UUID: NA' # Source VN if self._SOURCE_VN in flow_dict: source_vn = flow_dict[self._SOURCE_VN] else: source_vn = 'Source VN: NA' # Destination VN if self._DESTINATION_VN in flow_dict: destination_vn = flow_dict[self._DESTINATION_VN] else: destination_vn = 'Destination VN: NA' # Source IP if self._SOURCE_IP in flow_dict: source_ip = flow_dict[self._SOURCE_IP] else: source_ip = 'Source IP: NA' # Destination IP if self._DESTINATION_IP in flow_dict: destination_ip = flow_dict[self._DESTINATION_IP] else: destination_ip = 'Destination IP: NA' # Source port if self._SOURCE_PORT in flow_dict: source_port = flow_dict[self._SOURCE_PORT] else: source_port = 'Source Port: NA' # Destination port if self._DESTINATION_PORT in flow_dict: destination_port = flow_dict[self._DESTINATION_PORT] else: destination_port = 'Destination Port: NA' # Protocol if self._PROTOCOL in flow_dict: protocol = OpServerUtils.ip_protocol_to_str( int(flow_dict[self._PROTOCOL])) else: protocol = 'Protocol: NA' # Action if self._ACTION in flow_dict: action = flow_dict[self._ACTION] else: action = '' # Agg packets and bytes if VizConstants.FLOW_TABLE_AGG_BYTES in flow_dict: agg_bytes = int(flow_dict[VizConstants.FLOW_TABLE_AGG_BYTES]) else: agg_bytes = 'Agg Bytes: NA' if VizConstants.FLOW_TABLE_AGG_PKTS in flow_dict: agg_pkts = int(flow_dict[VizConstants.FLOW_TABLE_AGG_PKTS]) else: agg_pkts = 'Agg Packets: NA' print '{0}({1}) {2} [{3} -- {4}] {5} '\ '{6}:{7}:{8} ---> {9}:{10}:{11} [{12} P ({13} B)]'\ ' : {14}'.format( vrouter, direction, action, setup_ts, teardown_ts, protocol, source_vn, source_ip, source_port, destination_vn, destination_ip, destination_port, agg_pkts, agg_bytes, flow_uuid)
def display(self, result): if result == [] or result is None: return flow_dict_list = result for flow_dict in flow_dict_list: # Setup time if self._SETUP_TIME in flow_dict: setup_time = int(flow_dict[self._SETUP_TIME]) if setup_time != 0: setup_dt = datetime.datetime.fromtimestamp( setup_time / OpServerUtils.USECS_IN_SEC) setup_dt += datetime.timedelta( microseconds=(setup_time % OpServerUtils.USECS_IN_SEC)) setup_ts = setup_dt.strftime(OpServerUtils.TIME_FORMAT_STR) else: setup_ts = 'Setup Time: NA' else: setup_ts = 'Setup Time: NA' # Teardown time if self._TEARDOWN_TIME in flow_dict: teardown_time = int(flow_dict[self._TEARDOWN_TIME]) if teardown_time != 0: teardown_dt = datetime.datetime.fromtimestamp( teardown_time / OpServerUtils.USECS_IN_SEC) teardown_dt += datetime.timedelta( microseconds=(teardown_time % OpServerUtils.USECS_IN_SEC)) teardown_ts = teardown_dt.strftime( OpServerUtils.TIME_FORMAT_STR) else: teardown_ts = 'Active' else: teardown_ts = 'Active' # VRouter if self._VROUTER in flow_dict: vrouter = flow_dict[self._VROUTER] else: vrouter = 'VRouter: NA' # Direction if self._DIRECTION in flow_dict: direction = int(flow_dict[self._DIRECTION]) if direction == 1: direction = 'ingress' elif direction == 0: direction = 'egress' else: direction = 'Direction: Invalid' else: direction = 'Direction: NA' # Flow UUID if VizConstants.FLOW_TABLE_UUID in flow_dict: flow_uuid = flow_dict[VizConstants.FLOW_TABLE_UUID] else: flow_uuid = 'UUID: NA' # Source VN if self._SOURCE_VN in flow_dict: source_vn = flow_dict[self._SOURCE_VN] else: source_vn = 'Source VN: NA' # Destination VN if self._DESTINATION_VN in flow_dict: destination_vn = flow_dict[self._DESTINATION_VN] else: destination_vn = 'Destination VN: NA' # Source IP if self._SOURCE_IP in flow_dict: source_ip = flow_dict[self._SOURCE_IP] else: source_ip = 'Source IP: NA' # Destination IP if self._DESTINATION_IP in flow_dict: destination_ip = flow_dict[self._DESTINATION_IP] else: destination_ip = 'Destination IP: NA' # Source port if self._SOURCE_PORT in flow_dict: source_port = flow_dict[self._SOURCE_PORT] else: source_port = 'Source Port: NA' # Destination port if self._DESTINATION_PORT in flow_dict: destination_port = flow_dict[self._DESTINATION_PORT] else: destination_port = 'Destination Port: NA' # Protocol if self._PROTOCOL in flow_dict: protocol = OpServerUtils.ip_protocol_to_str( int(flow_dict[self._PROTOCOL])) else: protocol = 'Protocol: NA' # Action if self._ACTION in flow_dict: action = flow_dict[self._ACTION] else: action = '' # Agg packets and bytes if VizConstants.FLOW_TABLE_AGG_BYTES in flow_dict: agg_bytes = int(flow_dict[VizConstants.FLOW_TABLE_AGG_BYTES]) else: agg_bytes = 'Agg Bytes: NA' if VizConstants.FLOW_TABLE_AGG_PKTS in flow_dict: agg_pkts = int(flow_dict[VizConstants.FLOW_TABLE_AGG_PKTS]) else: agg_pkts = 'Agg Packets: NA' print '{0}({1}) {2} [{3} -- {4}] {5} '\ '{6}:{7}:{8} ---> {9}:{10}:{11} [{12} P ({13} B)]'\ ' : {14}'.format( vrouter, direction, action, setup_ts, teardown_ts, protocol, source_vn, source_ip, source_port, destination_vn, destination_ip, destination_port, agg_pkts, agg_bytes, flow_uuid)