<s> import time <EOL> import argparse <EOL> import os <EOL> import sys <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) ) <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> from pox . openflow . libopenflow_01 import * <EOL> from pox . lib . packet . ethernet import * <EOL> import sts . replay_event as replay_events <EOL> from sts . dataplane_traces . trace import Trace <EOL> from sts . input_traces . log_parser import parse <EOL> from sts . fingerprints . messages import DPFingerprint <EOL> from tools . pretty_print_input_trace import field_formatters , default_fields <EOL> def ti_filter ( e , pkt_fingerprint ) : <EOL> return DPFingerprint . from_pkt ( e . dp_event . packet ) == pkt_fingerprint <EOL> dp_ofp_packets = set ( [ ofp_packet_in , ofp_packet_out ] ) <EOL> def control_message_filter ( e , pkt_fingerprint ) : <EOL> of_pkt = e . get_packet ( ) <EOL> if type ( of_pkt ) not in dp_ofp_packets : <EOL> return False <EOL> return DPFingerprint . from_pkt ( ethernet ( raw = of_pkt . data ) ) == pkt_fingerprint <EOL> def dp_forward_filter ( e , pkt_fingerprint ) : <EOL> return e . dp_fingerprint == pkt_fingerprint <EOL> def process_flow_mod_filter ( e , pkt_fingerprint ) : <EOL> pass <EOL> dp_class_to_filter = { <EOL> replay_events . TrafficInjection : ti_filter , <EOL> replay_events . ControlMessageReceive : control_message_filter , <EOL> replay_events . ControlMessageSend : control_message_filter , <EOL> replay_events . DataplanePermit : dp_forward_filter , <EOL> replay_events . DataplaneDrop : dp_forward_filter , <EOL> replay_events . ProcessFlowMod : process_flow_mod_filter , <EOL> } <EOL> def main ( args ) : <EOL> with open ( args . input ) as input_file : <EOL> trace = parse ( input_file ) <EOL> while len ( trace ) > <NUM_LIT:0> and trace [ <NUM_LIT:0> ] . label_id < args . ti_id : <EOL> trace . pop ( <NUM_LIT:0> ) <EOL> ti_event = trace [ <NUM_LIT:0> ] <EOL> if type ( ti_event ) != replay_events . TrafficInjection : <EOL> raise ValueError ( "<STR_LIT>" % str ( ti_event ) ) <EOL> pkt_fingerprint = DPFingerprint . from_pkt ( ti_event . dp_event . packet ) <EOL> for event in trace : <EOL> t = type ( event ) <EOL> if t in dp_class_to_filter and dp_class_to_filter [ t ] ( event , pkt_fingerprint ) : <EOL> for field in default_fields : <EOL> field_formatters [ field ] ( event ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT:input>' , metavar = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , metavar = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> if args . ti_id [ <NUM_LIT:0> ] == "<STR_LIT:e>" or args . ti_id [ <NUM_LIT:0> ] == "<STR_LIT:i>" : <EOL> args . ti_id = args . ti_id [ <NUM_LIT:1> : ] <EOL> args . ti_id = int ( args . ti_id ) <EOL> main ( args ) </s>
