-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXMLparser_for_rt-dest.py
More file actions
47 lines (31 loc) · 1.04 KB
/
Copy pathXMLparser_for_rt-dest.py
File metadata and controls
47 lines (31 loc) · 1.04 KB
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
#!/usr/bin/python
import xml.dom.minidom
import os
infile = open('AWS16509.xml', 'r')
outfile = open('paths.txt.tmp', 'w')
def parseXML():
doc = xml.dom.minidom.parse(infile)
destinations = doc.getElementsByTagName("rt-destination")
aspaths = doc.getElementsByTagName("as-path")
for dest in destinations:
# outfile.write(dest.childNodes[0].nodeValue)
print >> outfile, dest.childNodes[0].nodeValue
print "There are", destinations.length, "destinations reachable through ", aspaths.length, 'paths.'
infile.close()
outfile.close()
def sortanduniq():
'''
the first generation of this process generates an AS path graph of deduplicated
paths from source to the specified AS. In order to do this, the cleaned file must
be sorted, and then run through 'uniq'
:return:
'''
# is there a python way to do this?
os.system('cat paths.txt.tmp | sort | uniq > final.txt')
def cleanup():
# delete working temp files
return
def main():
parseXML()
sortanduniq()
main()