Skip to content

Commit dff6c0b

Browse files
committed
Push changes
1 parent 87110c7 commit dff6c0b

File tree

7 files changed

+86
-117
lines changed

7 files changed

+86
-117
lines changed

batfish_mininet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ def post_build(hosts):
412412
# h50.cmd(f"iptables -t nat -I POSTROUTING -o {h50_h50r_link.intf1} -j SNAT --to 11.0.0.50")
413413
# h51.cmd(f"iptables -t nat -I POSTROUTING -o {h51_h50r_link.intf1} -j SNAT --to 11.1.0.51")
414414

415-
def post_start(hosts):
416-
for host in hosts.values():
415+
def post_start(hosts): #
416+
for host in hosts.values(): #
417417
inst = host["instance"]
418418
inst.cmd("ip route add 11.0.0.0/8 via 10.0.0.50")
419419
h52.cmd("ip route add 10.0.0.0/8 via 11.0.0.1")

batfish_mininet_template.py

+14-88
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
OVSKernelSwitch,
2323
Switch,
2424
DynamipsRouter,
25-
DynamipsHostRouter,
2625
)
2726
from mtv.node import Node as MTVNode
2827

@@ -89,15 +88,15 @@ def do_inferred_topo():
8988
"s13": {"params": {"name": "s13", "dpid": "000000000000000d"}},
9089
}
9190
hosts = {
92-
"h7": {"params": {"name": "h7", "ip": "10.0.0.7/24"}},
93-
"h9": {"params": {"name": "h9", "ip": "10.0.0.9/24"}},
94-
"h6": {"params": {"name": "h6", "ip": "10.0.0.6/24"}},
95-
"h5": {"params": {"name": "h5", "ip": "10.0.0.5/24"}},
96-
"h3": {"params": {"name": "h3", "ip": "10.0.0.3/24"}},
97-
"h4": {"params": {"name": "h4", "ip": "10.0.0.4/24"}},
98-
"h1": {"params": {"name": "h1", "ip": "10.0.0.1/24"}},
99-
"h2": {"params": {"name": "h2", "ip": "10.0.0.2/24"}},
100-
"h8": {"params": {"name": "h8", "ip": "10.0.0.8/24"}},
91+
"h7": {"params": {"name": "h7", "ip": "10.0.0.7", "mac": "00:00:00:00:00:07"}},
92+
"h9": {"params": {"name": "h9", "ip": "10.0.0.9", "mac": "00:00:00:00:00:09"}},
93+
"h6": {"params": {"name": "h6", "ip": "10.0.0.6", "mac": "00:00:00:00:00:06"}},
94+
"h5": {"params": {"name": "h5", "ip": "10.0.0.5", "mac": "00:00:00:00:00:05"}},
95+
"h3": {"params": {"name": "h3", "ip": "10.0.0.3", "mac": "00:00:00:00:00:03"}},
96+
"h4": {"params": {"name": "h4", "ip": "10.0.0.4", "mac": "00:00:00:00:00:04"}},
97+
"h1": {"params": {"name": "h1", "ip": "10.0.0.1", "mac": "00:00:00:00:00:01"}},
98+
"h2": {"params": {"name": "h2", "ip": "10.0.0.2", "mac": "00:00:00:00:00:02"}},
99+
"h8": {"params": {"name": "h8", "ip": "10.0.0.8", "mac": "00:00:00:00:00:08"}},
101100
}
102101
switch_links = [
103102
[{"name": "s10", "port": 6}, {"name": "s13", "port": 3}],
@@ -200,9 +199,12 @@ def post_build():
200199

201200
inst = host["instance"]
202201
inst.cmd(f"ip route add 2.128.0.0/24 via 10.0.0.7")
203-
inst.cmd(f"ip route add 2.128.1.0/24 via 10.0.0.7")
202+
inst.cmd(f"ip route add 2.128.1.0/24 via 10.0.0.8")
204203

205204
hosts["h7"]["instance"].cmd(f"iptables -t nat -I POSTROUTING -o h7-eth1 -j SNAT --to 2.128.0.101")
205+
hosts["h8"]["instance"].cmd(f"iptables -t nat -I POSTROUTING -o h8-eth1 -j SNAT --to 2.128.1.101")
206+
hosts["h7"]["instance"].cmd(f"ip route add 2.128.1.0/24 via 10.0.0.8")
207+
hosts["h8"]["instance"].cmd(f"ip route add 2.128.0.0/24 via 10.0.0.7")
206208

207209
c1.start()
208210

@@ -353,93 +355,17 @@ def post_start():
353355

354356
return post_start
355357

356-
def add_inter():
357-
root_dir = Path("/extra/")
358-
dynamips_image = str(root_dir / "c7200-adventerprisek9-mz.153-3.XB12.image")
359-
360-
h50 = net.addHost("h50", ip="10.0.0.50/24")
361-
net.addLink("s6", h50, port2=2, addr2="00:00:00")
362-
363-
normal_config = """hostname h50r
364-
ip routing
365-
router rip
366-
version 2
367-
network 10.0.0.0
368-
network 11.0.0.0
369-
interface FastEthernet 1/0
370-
no cdp enable
371-
ip address 10.0.0.50 255.0.0.0
372-
no shut
373-
interface GigabitEthernet 2/0
374-
no cdp enable
375-
ip address 10.0.0.50 255.0.0.0
376-
shut
377-
interface FastEthernet 3/0
378-
no cdp enable
379-
ip address 11.0.0.1 255.0.0.0
380-
no shut
381-
end"""
382-
config = config_patches.get("h50r", normal_config)
383-
384-
h50r = net.addHost(
385-
"h50r",
386-
ip="10.0.0.50",
387-
cls=DynamipsHostRouter,
388-
dynamips_platform="7200",
389-
dynamips_image=dynamips_image,
390-
dynamips_console_port=7123,
391-
dynamips_args=[
392-
"-i {}".format("h10"),
393-
"--idle-pc=0x60630338",
394-
"-P 7200",
395-
"-o 64",
396-
"-r 200",
397-
],
398-
dynamips_config=config,
399-
dynamips_ports=[("PA-FE-TX", "FastEthernet", 1, [(0, "s6")]),
400-
("PA-GE", "GigabitEthernet", 2, [(0, "s7")]),
401-
("PA-FE-TX", "FastEthernet", 3, [(0, "h52")])],
402-
)
403-
404-
h52 = net.addHost("h52", ip="11.0.0.52/8")
405-
s6_h50r_link = net.addLink("s6", h50r, addr2="00:00:00:00:00:32")
406-
s7_h50r_link = net.addLink("s7", h50r, addr2="00:00:00:00:00:33")
407-
h52_h50r_link = net.addLink(h52, h50r)
408-
409-
def post_build(hosts):
410-
pass
411-
# h50r.setIP("10.0.0.50", intf=)
412-
413-
# h50.setIP("11.0.0.50/8", intf=h50_h50r_link.intf1)
414-
# h51.setIP("11.1.0.51/8", intf=h51_h50r_link.intf1)
415-
# h52.setIP("11.2.0.52/8", intf=h52_h50r_link.intf1)
416-
# h52.cmd("ip route add 10.0.0.0/8 via 11.0.0.1")
417-
# h50.cmd(f"iptables -t nat -I POSTROUTING -o {h50_h50r_link.intf1} -j SNAT --to 11.0.0.50")
418-
# h51.cmd(f"iptables -t nat -I POSTROUTING -o {h51_h50r_link.intf1} -j SNAT --to 11.1.0.51")
419-
420-
def post_start(hosts):
421-
for host in hosts.values():
422-
inst = host["instance"]
423-
inst.cmd("ip route add 11.0.0.0/8 via 10.0.0.50")
424-
h52.cmd("ip route add 10.0.0.0/8 via 11.0.0.1")
425-
h50r.start()
426-
427-
return post_build, post_start
428-
429358
# h1 ip r add 2.128.0.0/24 via 10.0.0.2
430359
# h1 ip r add 2.128.1.0/24 via 10.0.0.2
431360

432361
post_build, hosts = do_inferred_topo()
433362
post_start = do_batfish()
434-
post_build_inter, post_start_inter = add_inter()
435363

436364
net.build()
437365
post_build()
438-
post_build_inter(hosts)
439366
net.start()
440-
#net.staticArp()
367+
net.staticArp()
441368
post_start()
442-
post_start_inter(hosts)
443369
REST(net)
444370

445371
exit = Event()

do_ssh.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
2-
ssh -N -L 8181:localhost:8181 -L 5000:localhost:5000 \
3-
-L 172.17.0.1:8181:localhost:8181 -L 172.17.0.1:5000:localhost:5000 \
2+
ssh -N -L 8181:localhost:8181 -L 5000:localhost:5000 -L 7123:localhost:7123 \
3+
-L 172.17.0.1:8181:localhost:8181 -L 172.17.0.1:5000:localhost:5000 -L 172.17.0.1:7123:localhost:7123 \
44
mongo

intent_deployer/deploy.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ async def deploy_policy(url: URL, policy: Policy):
2626

2727
if not resp.status_code in range(200, 300):
2828
raise IntentDeployException("Policy deployment failed") from e
29-
return resp.json()
29+
r = resp.json()
30+
print(url, r)
31+
return r

intent_deployer/network_state.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ async def is_spp() -> bool:
438438
str(config.ngcdi_url / "is_spp"),
439439
)
440440
resp.raise_for_status()
441-
return resp.json()["spp"]
441+
spp = resp.json()["spp"]
442+
print(spp)
443+
return spp
442444

443445

444446
app_id: Optional[int] = None

intents/upgrade.py

+55-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from intent_deployer.hosts import Hosts
88
from intent_deployer.notifiers import NullNotifier
99
from intent_deployer.dialogflow import DialogflowContext
10+
from telnetlib import Telnet
1011

1112
import logging
1213
from typing import Any
@@ -32,9 +33,33 @@
3233

3334

3435
config_files = {
35-
"known_broken": """
36-
hostname h50
36+
"upgrade_speed": """
37+
enable
38+
conf t
39+
ip routing
40+
router rip
41+
interface FastEthernet 1/0
42+
shut
43+
interface GigabitEthernet 2/0
44+
no cdp enable
45+
ip address 10.0.0.50 255.0.0.0
46+
no shut
3747
end
48+
disable
49+
""",
50+
"downgrade_speed": """
51+
enable
52+
conf t
53+
ip routing
54+
router rip
55+
interface FastEthernet 1/0
56+
no cdp enable
57+
ip address 10.0.0.50 255.0.0.0
58+
no shut
59+
interface GigabitEthernet 2/0
60+
shut
61+
end
62+
disable
3863
"""
3964
}
4065

@@ -63,7 +88,6 @@ def handle_dialogflow_upgrade_intent(params: dict[str, Any]) -> UpgradeIntent:
6388
def handle_dialogflow_downgrade_intent(params: dict[str, Any]) -> DowngradeIntent:
6489
return DowngradeIntent(**params)
6590

66-
6791
@register_intent_executor(UpgradeIntent)
6892
async def handle_upgrade_intent(ctx: Context, intent: UpgradeIntent):
6993
await raise_if_spp()
@@ -77,24 +101,37 @@ async def handle_upgrade_intent(ctx: Context, intent: UpgradeIntent):
77101
)
78102

79103
async def upgrade_intent_test_followup():
104+
with Telnet("172.17.0.1", 7123) as tn:
105+
x = tn.read_until(b"_________", timeout=3)
106+
print(x.decode(), end="")
107+
for line in config.split("\n"):
108+
tn.write(line.encode("ascii") + b"\r\n")
109+
x = tn.read_until(b"#", timeout=3)
110+
print(x.decode(), end="")
111+
tn.read_until(b"#", timeout=3)
80112
if isinstance(ctx, DialogflowContext):
81113
notifier = ctx.get_notifier()
82114
if notifier is not None:
83-
await notifier.send("Testing configuration, please wait")
84-
85-
runner = NEATRunner.generate_mtv_config(topology, {intent.hostname: config})
86-
success = await runner.run()
87-
88-
if success:
89-
if isinstance(ctx, DialogflowContext):
90-
notifier = ctx.get_notifier()
91-
if notifier is not None:
92-
await notifier.send("Tests passed, applying intent")
93-
await apply_config_upgrade(ctx, intent)
94-
if not success:
95-
raise IntentDeployException(
96-
"After testing the new configuration the tests did not pass, abandoning"
97-
)
115+
await notifier.send("Reconfigured router!")
116+
117+
# if isinstance(ctx, DialogflowContext):
118+
# notifier = ctx.get_notifier()
119+
# if notifier is not None:
120+
# await notifier.send("Testing configuration, please wait")
121+
122+
# runner = NEATRunner.generate_mtv_config(topology, {intent.hostname: config})
123+
# success = await runner.run()
124+
125+
# if success:
126+
# if isinstance(ctx, DialogflowContext):
127+
# notifier = ctx.get_notifier()
128+
# if notifier is not None:
129+
# await notifier.send("Tests passed, applying intent")
130+
# await apply_config_upgrade(ctx, intent)
131+
# if not success:
132+
# raise IntentDeployException(
133+
# "After testing the new configuration the tests did not pass, abandoning"
134+
# )
98135

99136
await ctx.confirm_if_needed(
100137
f"This will reconfigure router {intent.hostname} to use the config '{intent.config}'",

neat_integration/invokation.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ def generate_mtv_config(
286286

287287
tests = []
288288
for src, dst in itertools.permutations(topology.hosts.hostnames, 2):
289-
# temp hack, the router can be pinged, but cannot ping
290-
if src in ["h50"] or dst in ["h50"]:
289+
# temp hack
290+
if src in ["h50", "h28"] or dst in ["h50", "h28"]:
291291
continue
292292

293293
test = NEATTest(
@@ -304,10 +304,12 @@ def generate_mtv_config(
304304
# network
305305
for src, dst in itertools.product(
306306
topology.hosts.hostnames,
307-
["2.128.0.1", "2.128.0.101", "2.128.1.1", "2.128.1.101", "11.0.0.52"],
307+
["2.128.0.1", "2.128.0.101", "2.128.1.1", "2.128.1.101"],
308308
):
309-
# temp hack, the router can be pinged, but cannot ping
310-
if src in ["h50"]:
309+
# temp hack
310+
if src in ["h50", "h28"]:
311+
continue
312+
if dst in ["h50", "h28"]:
311313
continue
312314

313315
test = NEATTest(

0 commit comments

Comments
 (0)