summaryrefslogtreecommitdiffstats
path: root/scripts/doc_process.py
blob: d371cc02982c2713f36213bec930fffe78ef0490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import sys,os
import re
import argparse


class doc_driver(object):
     args=None;

def  str_hex_to_ip(ip_hex):
    bytes = ["".join(x) for x in zip(*[iter(ip_hex)]*2)]
    bytes = [int(x, 16) for x in bytes]
    s=".".join(str(x) for x in bytes)
    return s

class CTemplateFile:
    def __init__ (self):
        self.l=[];

    def dump (self):
        print "pkt,time sec,template,fid,flow-pkt-id,client_ip,client_port,server_ip ,desc"
        for obj in self.l:
            s='';
            if obj[7]=='1':
                s ='->'
            else:
                s ='<-'

            print obj[0],",",obj[1],",",obj[6],",", obj[2],",",obj[4],",",str_hex_to_ip(obj[11]),",",obj[13],",",str_hex_to_ip(obj[12]),",",s

    def dump_sj (self):
        flows=0;
        print "["
        for obj in self.l:
            print "[",
            print obj[1],",",int("0x"+obj[2],16),",",obj[6],",",obj[4],
            print "],"

        print "]"



    def load_file (self,file):
        f=open(file,'r');
        x=f.readlines()
        f.close();
        found=False;
        for line in x:
            if found :
               line=line.rstrip('\n');
               info=line.split(',');
               if len(info)>5:
                   self.l+=[info];
               else:
                   break;
            else:
                if 'pkt_id' in line:
                    found=True;




def do_main ():
    temp = CTemplateFile();
    temp.load_file(doc_driver.args.file)
    temp.dump();
    temp.dump_sj();


def process_options ():
    parser = argparse.ArgumentParser(usage=""" 
    doc_process -f <debug_output> 
    """,
    description="process bp-sim output for docomentation",
    epilog=" written by hhaim");

    parser.add_argument("-f", "--file", dest="file",
                        metavar="file",
                        required=True)

    parser.add_argument('--version', action='version',
                        version="0.1" )

    doc_driver.args = parser.parse_args();



def main ():
    try:
        process_options ();
        do_main ()
        exit(0);
    except Exception, e:
        print str(e);
        exit(-1);



if __name__ == "__main__":
    main()