Skip to content

Commit 7c10d95

Browse files
committed
Remove soft links and make config.py a module
1 parent 74e8a80 commit 7c10d95

File tree

20 files changed

+191
-156
lines changed

20 files changed

+191
-156
lines changed

examples/01-subnet-isolation/confgen.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/python3
22

3+
import os
34
import sys
45
import argparse
6+
7+
sys.path.append(os.path.join(os.path.dirname(__file__), '../../src'))
58
from config import *
69

710

811
def confgen(subnets, hosts, fault):
9-
network = Network()
12+
config = Config()
1013

1114
## firewall rules
1215
fw_rules = """
@@ -38,7 +41,7 @@ def confgen(subnets, hosts, fault):
3841
internet_node.add_static_route(Route('10.0.0.0/8', '8.0.0.2'))
3942
internet_node.add_static_route(Route('11.0.0.0/8', '8.0.0.2'))
4043
internet_node.add_static_route(Route('12.0.0.0/8', '8.0.0.2'))
41-
network.add_node(internet_node)
44+
config.add_node(internet_node)
4245
fw = Middlebox('fw', 'netns', 'netfilter')
4346
fw.add_interface(Interface('eth0', '8.0.0.2/24'))
4447
fw.add_interface(Interface('eth1', '9.0.0.1/24'))
@@ -51,7 +54,7 @@ def confgen(subnets, hosts, fault):
5154
fw.add_config('rules', fw_bad_rules)
5255
else:
5356
fw.add_config('rules', fw_rules)
54-
network.add_node(fw)
57+
config.add_node(fw)
5558
gw = Node('gw')
5659
gw.add_interface(Interface('eth0', '9.0.0.2/24'))
5760
for subnet in range(subnets): # add "public"-connecting interfaces
@@ -66,18 +69,18 @@ def confgen(subnets, hosts, fault):
6669
'10.%d.0.1/16' % subnet)
6770
gw.add_interface(intf)
6871
gw.add_static_route(Route('0.0.0.0/0', '9.0.0.1'))
69-
network.add_node(gw)
70-
network.add_link(Link('internet', 'eth0', 'fw', 'eth0'))
71-
network.add_link(Link('fw', 'eth1', 'gw', 'eth0'))
72+
config.add_node(gw)
73+
config.add_link(Link('internet', 'eth0', 'fw', 'eth0'))
74+
config.add_link(Link('fw', 'eth1', 'gw', 'eth0'))
7275

7376
## add nodes and links in the public subnets
7477
for subnet in range(subnets):
7578
sw = Node('public%d-sw' % subnet)
7679
sw.add_interface(Interface('eth0'))
7780
for i in range(1, hosts + 1):
7881
sw.add_interface(Interface('eth%d' % i))
79-
network.add_node(sw)
80-
network.add_link(Link(sw.name, 'eth0', 'gw', 'eth%d' % (subnet + 1)))
82+
config.add_node(sw)
83+
config.add_link(Link(sw.name, 'eth0', 'gw', 'eth%d' % (subnet + 1)))
8184
for i in range(1, hosts + 1):
8285
host = Node('public%d-host%d' % (subnet, i - 1))
8386
second_last = ((i + 1) // 256) % 256
@@ -86,17 +89,17 @@ def confgen(subnets, hosts, fault):
8689
Interface('eth0',
8790
'12.%d.%d.%d/16' % (subnet, second_last, last)))
8891
host.add_static_route(Route('0.0.0.0/0', '12.%d.0.1' % subnet))
89-
network.add_node(host)
90-
network.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
92+
config.add_node(host)
93+
config.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
9194

9295
## add nodes and links in the private subnets
9396
for subnet in range(subnets):
9497
sw = Node('private%d-sw' % subnet)
9598
sw.add_interface(Interface('eth0'))
9699
for i in range(1, hosts + 1):
97100
sw.add_interface(Interface('eth%d' % i))
98-
network.add_node(sw)
99-
network.add_link(
101+
config.add_node(sw)
102+
config.add_link(
100103
Link(sw.name, 'eth0', 'gw', 'eth%d' % (subnet + 1 + subnets)))
101104
for i in range(1, hosts + 1):
102105
host = Node('private%d-host%d' % (subnet, i - 1))
@@ -106,17 +109,17 @@ def confgen(subnets, hosts, fault):
106109
Interface('eth0',
107110
'11.%d.%d.%d/16' % (subnet, second_last, last)))
108111
host.add_static_route(Route('0.0.0.0/0', '11.%d.0.1' % subnet))
109-
network.add_node(host)
110-
network.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
112+
config.add_node(host)
113+
config.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
111114

112115
## add nodes and links in the quarantined subnets
113116
for subnet in range(subnets):
114117
sw = Node('quarantined%d-sw' % subnet)
115118
sw.add_interface(Interface('eth0'))
116119
for i in range(1, hosts + 1):
117120
sw.add_interface(Interface('eth%d' % i))
118-
network.add_node(sw)
119-
network.add_link(
121+
config.add_node(sw)
122+
config.add_link(
120123
Link(sw.name, 'eth0', 'gw', 'eth%d' % (subnet + 1 + subnets * 2)))
121124
for i in range(1, hosts + 1):
122125
host = Node('quarantined%d-host%d' % (subnet, i - 1))
@@ -126,13 +129,12 @@ def confgen(subnets, hosts, fault):
126129
Interface('eth0',
127130
'10.%d.%d.%d/16' % (subnet, second_last, last)))
128131
host.add_static_route(Route('0.0.0.0/0', '10.%d.0.1' % subnet))
129-
network.add_node(host)
130-
network.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
132+
config.add_node(host)
133+
config.add_link(Link(host.name, 'eth0', sw.name, 'eth%d' % i))
131134

132135
## add policies
133-
policies = Policies()
134136
# public subnets can initiate connections to the outside world
135-
policies.add_policy(
137+
config.add_policy(
136138
ReachabilityPolicy(target_node='internet',
137139
reachable=True,
138140
protocol='tcp',
@@ -141,7 +143,7 @@ def confgen(subnets, hosts, fault):
141143
dst_port=[80],
142144
owned_dst_only=True))
143145
# public subnets can accept connections from the outside world
144-
policies.add_policy(
146+
config.add_policy(
145147
ReachabilityPolicy(target_node='(public.*-host.*)|gw',
146148
reachable=True,
147149
protocol='tcp',
@@ -151,7 +153,7 @@ def confgen(subnets, hosts, fault):
151153
owned_dst_only=True))
152154
# private subnets can initiate connections to the outside world and replies
153155
# from the outside world can reach the private subnets
154-
policies.add_policy(
156+
config.add_policy(
155157
ReplyReachabilityPolicy(target_node='internet',
156158
reachable=True,
157159
protocol='tcp',
@@ -160,7 +162,7 @@ def confgen(subnets, hosts, fault):
160162
dst_port=[80],
161163
owned_dst_only=True))
162164
# private subnets can't accept connections from the outside world
163-
policies.add_policy(
165+
config.add_policy(
164166
ReachabilityPolicy(target_node='(private.*-host.*)|gw',
165167
reachable=False,
166168
protocol='tcp',
@@ -169,7 +171,7 @@ def confgen(subnets, hosts, fault):
169171
dst_port=[80],
170172
owned_dst_only=True))
171173
# quarantined subnets can't initiate connections to the outside world
172-
policies.add_policy(
174+
config.add_policy(
173175
ReachabilityPolicy(target_node='internet',
174176
reachable=False,
175177
protocol='tcp',
@@ -178,7 +180,7 @@ def confgen(subnets, hosts, fault):
178180
dst_port=[80],
179181
owned_dst_only=True))
180182
# quarantined subnets can't accept connections from the outside world
181-
policies.add_policy(
183+
config.add_policy(
182184
ReachabilityPolicy(target_node='(quarantined.*-host.*)|gw',
183185
reachable=False,
184186
protocol='tcp',
@@ -188,7 +190,7 @@ def confgen(subnets, hosts, fault):
188190
owned_dst_only=True))
189191

190192
## output as TOML
191-
output_toml(network, None, policies)
193+
config.output_toml()
192194

193195

194196
def main():

examples/01-subnet-isolation/config.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/01-subnet-isolation/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ for subnets in 4 8 10 12; do
2020
sudo chown -R "$(id -u):$(id -g)" "$RESULTS_DIR/$name"
2121
cp "$CONF" "$RESULTS_DIR/$name"
2222
done
23+
rm "$CONF"
2324
done
2425

2526
# faulty configuration
@@ -40,6 +41,7 @@ for subnets in 4 8 10 12; do
4041
sudo chown -R "$(id -u):$(id -g)" "$RESULTS_DIR/$name"
4142
cp "$CONF" "$RESULTS_DIR/$name"
4243
done
44+
rm "$CONF"
4345
done
4446

4547
# msg "Populating measurements..."

examples/02-firewall-consistency/confgen.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/python3
22

3+
import os
34
import sys
4-
import toml
55
import argparse
6+
7+
sys.path.append(os.path.join(os.path.dirname(__file__), '../../src'))
68
from config import *
79

810

911
def confgen(apps, hosts, fault):
10-
network = Network()
12+
config = Config()
1113

1214
## set firewall rules
1315
fw_rules = """
@@ -81,22 +83,22 @@ def confgen(apps, hosts, fault):
8183
agg2_source = Node('agg2-source')
8284
agg2_source.add_interface(Interface('eth0', '8.0.7.2/24'))
8385
agg2_source.add_interface(Interface('eth1', '8.0.5.2/24'))
84-
network.add_node(core1)
85-
network.add_node(agg1_sink)
86-
network.add_node(fw1)
87-
network.add_node(agg1_source)
88-
network.add_node(core2)
89-
network.add_node(agg2_sink)
90-
network.add_node(fw2)
91-
network.add_node(agg2_source)
92-
network.add_link(Link('core1', 'eth0', 'agg1-sink', 'eth1'))
93-
network.add_link(Link('core1', 'eth1', 'agg1-source', 'eth1'))
94-
network.add_link(Link('agg1-sink', 'eth0', 'fw1', 'eth0'))
95-
network.add_link(Link('agg1-source', 'eth0', 'fw1', 'eth1'))
96-
network.add_link(Link('core2', 'eth0', 'agg2-sink', 'eth1'))
97-
network.add_link(Link('core2', 'eth1', 'agg2-source', 'eth1'))
98-
network.add_link(Link('agg2-sink', 'eth0', 'fw2', 'eth0'))
99-
network.add_link(Link('agg2-source', 'eth0', 'fw2', 'eth1'))
86+
config.add_node(core1)
87+
config.add_node(agg1_sink)
88+
config.add_node(fw1)
89+
config.add_node(agg1_source)
90+
config.add_node(core2)
91+
config.add_node(agg2_sink)
92+
config.add_node(fw2)
93+
config.add_node(agg2_source)
94+
config.add_link(Link('core1', 'eth0', 'agg1-sink', 'eth1'))
95+
config.add_link(Link('core1', 'eth1', 'agg1-source', 'eth1'))
96+
config.add_link(Link('agg1-sink', 'eth0', 'fw1', 'eth0'))
97+
config.add_link(Link('agg1-source', 'eth0', 'fw1', 'eth1'))
98+
config.add_link(Link('core2', 'eth0', 'agg2-sink', 'eth1'))
99+
config.add_link(Link('core2', 'eth1', 'agg2-source', 'eth1'))
100+
config.add_link(Link('agg2-sink', 'eth0', 'fw2', 'eth0'))
101+
config.add_link(Link('agg2-source', 'eth0', 'fw2', 'eth1'))
100102

101103
for app in range(apps):
102104
## add access nodes/links
@@ -164,23 +166,23 @@ def confgen(apps, hosts, fault):
164166
Route('0.0.0.0/0', '9.%d.%d.5' % (second, third)))
165167
access2.add_static_route(
166168
Route('0.0.0.0/0', '9.%d.%d.21' % (second, third)))
167-
network.add_node(access1)
168-
network.add_node(access2)
169-
network.add_link(
169+
config.add_node(access1)
170+
config.add_node(access2)
171+
config.add_link(
170172
Link(access1.name, 'eth0', 'agg1-sink', 'eth%d' % (2 * app + 2)))
171-
network.add_link(
173+
config.add_link(
172174
Link(access1.name, 'eth1', 'agg1-source', 'eth%d' % (2 * app + 2)))
173-
network.add_link(
175+
config.add_link(
174176
Link(access1.name, 'eth2', 'agg2-sink', 'eth%d' % (2 * app + 2)))
175-
network.add_link(
177+
config.add_link(
176178
Link(access1.name, 'eth3', 'agg2-source', 'eth%d' % (2 * app + 2)))
177-
network.add_link(
179+
config.add_link(
178180
Link(access2.name, 'eth0', 'agg1-sink', 'eth%d' % (2 * app + 3)))
179-
network.add_link(
181+
config.add_link(
180182
Link(access2.name, 'eth1', 'agg1-source', 'eth%d' % (2 * app + 3)))
181-
network.add_link(
183+
config.add_link(
182184
Link(access2.name, 'eth2', 'agg2-sink', 'eth%d' % (2 * app + 3)))
183-
network.add_link(
185+
config.add_link(
184186
Link(access2.name, 'eth3', 'agg2-source', 'eth%d' % (2 * app + 3)))
185187

186188
## add application hosts and related nodes/links
@@ -198,7 +200,7 @@ def confgen(apps, hosts, fault):
198200
node.add_static_route(
199201
Route('0.0.0.0/0',
200202
'10.%d.%d.%d' % (second, third, last - 1)))
201-
network.add_link(
203+
config.add_link(
202204
Link(node.name, 'eth0', access1.name,
203205
'eth%d' % acc_intf_num))
204206
elif host % 2 == 1: # hosts under access2
@@ -211,13 +213,12 @@ def confgen(apps, hosts, fault):
211213
node.add_static_route(
212214
Route('0.0.0.0/0',
213215
'11.%d.%d.%d' % (second, third, last - 1)))
214-
network.add_link(
216+
config.add_link(
215217
Link(node.name, 'eth0', access2.name,
216218
'eth%d' % acc_intf_num))
217-
network.add_node(node)
219+
config.add_node(node)
218220

219221
## add policies
220-
policies = Policies()
221222
for app in range(apps):
222223
second = (app // 256) % 256 # second octet
223224
third = app % 256 # third octet
@@ -245,7 +246,7 @@ def confgen(apps, hosts, fault):
245246
for i in other_apps]))))
246247
# In the same application, hosts under access1 can reach hosts under
247248
# access2
248-
policies.add_policy(
249+
config.add_policy(
249250
ConsistencyPolicy([
250251
ReachabilityPolicy(target_node=hosts_acc2 +
251252
'|access2-app%d' % app,
@@ -258,7 +259,7 @@ def confgen(apps, hosts, fault):
258259
]))
259260
# In the same application, hosts under access2 can reach hosts under
260261
# access1
261-
policies.add_policy(
262+
config.add_policy(
262263
ConsistencyPolicy([
263264
ReachabilityPolicy(target_node=hosts_acc1 +
264265
'|access1-app%d' % app,
@@ -270,7 +271,7 @@ def confgen(apps, hosts, fault):
270271
owned_dst_only=True)
271272
]))
272273
# Hosts of an application cannot reach hosts of other applications
273-
policies.add_policy(
274+
config.add_policy(
274275
ConsistencyPolicy([
275276
ReachabilityPolicy(target_node=hosts_other_apps,
276277
reachable=False,
@@ -283,7 +284,7 @@ def confgen(apps, hosts, fault):
283284
break
284285

285286
## output as TOML
286-
output_toml(network, None, policies)
287+
config.output_toml()
287288

288289

289290
def main():

examples/02-firewall-consistency/config.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/02-firewall-consistency/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ for apps in 4 8 10 12; do
2020
sudo chown -R "$(id -u):$(id -g)" "$RESULTS_DIR/$name"
2121
cp "$CONF" "$RESULTS_DIR/$name"
2222
done
23+
rm "$CONF"
2324
done
2425

2526
# faulty configuration
@@ -40,6 +41,7 @@ for apps in 4 8 10 12; do
4041
sudo chown -R "$(id -u):$(id -g)" "$RESULTS_DIR/$name"
4142
cp "$CONF" "$RESULTS_DIR/$name"
4243
done
44+
rm "$CONF"
4345
done
4446

4547
# msg "Populating measurements..."

0 commit comments

Comments
 (0)