-
Notifications
You must be signed in to change notification settings - Fork 0
/
workload.py
73 lines (61 loc) · 2.73 KB
/
workload.py
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
"""
This parses the input flows.csv file into a Workload
object that is used by other parts of the infrastructure
to setup and run the experiments
"""
import sys, os, re
import ipHostMap
BASE_PORT = 915
class Workload:
def __init__(self, flowsFile):
self.numLinksFormat = r'num_links: ([\d]*)'
self.linkCapFormat = r'link_capacities \(Gbps\): ([\d]*)'
self.flowFormat = r'(?P<srcIP>[\d\.]*),[ ]*(?P<dstIP>[\d\.]*) -> (?P<links>[ \d,]*)'
self.ipHostMap = ipHostMap.ipHostMap
# self.flows is a list with entries of the form:
# {'srcIP':'xx.xx.xx.xx', 'dstIP':'yy.yy.yy.yy', 'port':num, 'links':[x, y, z], 'srcHost':h1, 'dstHost':h2}
self.flows = []
self.numLinks = None
self.linkCap = None
self.numFlows = None
self.srcs = None
self.dsts = None
self.allIPs = None
self.allHosts = None
self.srcHosts = None
self.dstHosts = None
# parse the flowsFile
with open(flowsFile) as f:
doc = f.read()
# set self.num_links
searchObj = re.search(self.numLinksFormat, doc)
if searchObj is not None:
self.numLinks = int(searchObj.group(1))
else:
print >> sys.stderr, "ERROR: num_links not specified in flowsFile"
sys.exit(1)
# set self.link_capacities
searchObj = re.search(self.linkCapFormat, doc)
if searchObj is not None:
self.linkCap = int(searchObj.group(1))
else:
print >> sys.stderr, "ERROR: link_capacities not specified in flowsFile"
sys.exit(1)
# set self.flows
searchObj = re.search(self.flowFormat, doc)
while searchObj is not None:
self.flows.append(searchObj.groupdict())
doc = doc[:searchObj.start()] + doc[searchObj.end():]
searchObj = re.search(self.flowFormat, doc)
self.srcs = [flow['srcIP'] for flow in self.flows]
self.dsts = [flow['dstIP'] for flow in self.flows]
self.allIPs = self.srcs + list(set(self.dsts) - set(self.srcs))
self.allHosts = list(set([self.ipHostMap[IP] for IP in self.allIPs]))
self.srcHosts = list(set([self.ipHostMap[IP] for IP in self.srcs]))
self.dstHosts = list(set([self.ipHostMap[IP] for IP in self.dsts]))
self.numFlows = len(self.flows)
for i, flow in zip(range(len(self.flows)), self.flows):
flow['links'] = map(int, flow['links'].split(','))
flow['port'] = BASE_PORT + i
flow['srcHost'] = self.ipHostMap[flow['srcIP']]
flow['dstHost'] = self.ipHostMap[flow['dstIP']]