-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_srn.py
210 lines (169 loc) · 6.61 KB
/
test_srn.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import argparse
import datetime
import json
import os
import time
import ipmininet
import psutil
from ipmininet.clean import cleanup
from ipmininet.cli import IPCLI
from ipmininet.utils import realIntfList
from mininet.log import LEVELS, lg
from srnmininet.albilene import Albilene
from srnmininet.comp import CompTopo
from srnmininet.config.config import SRDNSProxy, SRRouted
from srnmininet.srnnet import SRNNet
from srnmininet.utils import daemon_in_node
components = ["sr-ctrl", "sr-routed", "sr-dnsproxy", "sr-nsd"]
# Argument parsing
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--log', choices=LEVELS.keys(), default='info',
help='The level of details in the logs.')
parser.add_argument('--log-dir', help='Logging directory root',
default='/tmp/logs-%s' % datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
parser.add_argument('--src-dir', help='Source directory root of SR components',
default='srn')
return parser.parse_args()
def test_dns_latency(link_delay):
cleanup()
log_dir = args.log_dir + "-%s" % link_delay
topo_args = {"schema_tables": full_schema["tables"],
"cwd": log_dir,
"link_delay": link_delay}
net = SRNNet(topo=CompTopo(**topo_args), static_routing=True)
try:
net.start()
client = net["comp2"]
server = net["comp6"]
dns_proxy_ip6 = None
for node in net.routers:
if daemon_in_node(node, SRDNSProxy) is not None:
dns_proxy_ip6 = node.intf("lo").ip6
lg.debug("SRDNSProxy address found was %s", dns_proxy_ip6)
if dns_proxy_ip6 is None:
raise Exception("Cannot find a global address for a node with SRDNSProxy")
time.sleep(10)
cmd = [sr_testdns, "sr", "10", server.name + ".test.sr", dns_proxy_ip6]
print(cmd)
IPCLI(net)
out = client.cmd(cmd)
with open(os.path.join(log_dir, "sr-testdns-%s-rtt.log" % link_delay), "w") as fileobj:
fileobj.write(str(out))
finally:
net.stop()
def map_pings_to_segments(source_node, destination_node, access_router):
dest_node_ip6 = None
for itf in realIntfList(destination_node):
for ip6 in itf.ip6s(exclude_lls=True):
dest_node_ip6 = ip6.ip.compressed
lg.debug("server address found was %s", dest_node_ip6)
if dest_node_ip6 is None:
raise Exception("Cannot find a global address for the server")
routed = daemon_in_node(access_router, SRRouted)
cmd = ["ip", "-6", "route", "show", "table", routed.localsid_name]
out = access_router.cmd(cmd)
lines = out.split("\n")
if len(lines) == 0:
raise Exception("Cannot find an encap rule in the %s of %s" % (routed.localsid_name, access_router.name))
bsid = lines[0].split(" ")[0]
print(lines[0])
cmd = ["ip", "-6", "route", "add", dest_node_ip6, "encap", "seg6", "mode", "inline", "segs", bsid,
"dev", realIntfList(source_node)[0].name]
print(" ".join(cmd))
out = source_node.cmd(cmd)
print(out)
return dest_node_ip6
def wait_access_router_start(node):
cmd = ["pgrep", "sr-routed"]
out = node.cmd(cmd)
pids = out.split("\n")
pids = [int(pid[:-1]) for pid in pids if len(pid) > 0]
if len(pids) == 0:
raise Exception("Cannot find sr-routed daemon")
for pid in pids:
p = psutil.Process(pid)
old_percentage = 100.0
while True:
percentage = p.cpu_percent(1)
if percentage < 20.0 and old_percentage < 20.0:
break
old_percentage = percentage
time.sleep(1)
def test_flapping_link():
cleanup()
topo_args = {"schema_tables": full_schema["tables"], "cwd": args.log_dir}
net = SRNNet(topo=Albilene(**topo_args))
try:
net.start()
# Create a binding segment
client = net["client"]
server = net["server"]
dns_proxy_ip6 = None
for node in net.routers:
if daemon_in_node(node, SRDNSProxy) is not None:
dns_proxy_ip6 = node.intf("lo").ip6
lg.debug("SRDNSProxy address found was %s", dns_proxy_ip6)
if dns_proxy_ip6 is None:
raise Exception("Cannot find a global address for a node with SRDNSProxy")
# Wait for IGP convergence
wait_access_router_start(client)
time.sleep(10)
cmd = [sr_testdns, "-d", "8", "sr", "1", server.name + ".test.sr", dns_proxy_ip6]
print(" ".join(cmd))
out, err, code = client.pexec(cmd)
print(out)
if code:
print(err)
print(code)
server_ip6 = map_pings_to_segments(client, server, net["A"])
# Return path
cmd = [sr_testdns, "-d", "8", "sr", "1", client.name + ".test.sr", dns_proxy_ip6]
print(" ".join(cmd))
out = server.cmd(cmd)
print(out)
map_pings_to_segments(server, client, net["F"])
print("*** Route was inserted")
IPCLI(net)
print("** Using 'ping6 %s' to test the discovered path **" % server_ip6)
cmd = ["ping6", "-c", "5", server_ip6]
out = client.cmd(cmd)
print(out)
# Make a link fail
cmd = ["ip", "link", "set", "B-eth0", "down"]
out = net["B"].cmd(cmd)
print(out)
print("*** The link A-B failed")
IPCLI(net)
print("** Using 'ping6 %s' to test after failure **" % server_ip6)
cmd = ["ping6", "-c", "5", server_ip6]
out = client.cmd(cmd)
print(out)
# Bring the link back up
cmd = ["ip", "link", "set", "B-eth0", "up"]
net["B"].cmd(cmd)
cmd = ["ip", "-6", "addr", "add", next(net["B"].intf("B-eth0").ip6s(exclude_lls=True)), "dev", "B-eth0"]
net["B"].cmd(cmd)
print("*** The link A-B is back up")
IPCLI(net)
print("** Using 'ping6 %s' to test the path when back up **" % server_ip6)
cmd = ["ping6", "-c", "5", server_ip6]
out = client.cmd(cmd)
print(out)
finally:
net.stop()
args = parse_args()
with open(os.path.join(args.src_dir, "sr.ovsschema"), "r") as fileobj:
full_schema = json.load(fileobj)
lg.setLogLevel(args.log)
if args.log == 'debug':
ipmininet.DEBUG_FLAG = True
sr_testdns = os.path.join(os.path.abspath(args.src_dir), "bin", "sr-testdns")
# Add SR components to PATH
os.environ["PATH"] += os.pathsep + os.path.join(os.path.abspath(args.src_dir), "bin")
# Give the database description to the topology
test_dns_latency("1ms")
test_dns_latency("5ms")
# TODO Plot
# Flapping link
# test_flapping_link()