Skip to content

Commit

Permalink
Merge pull request #17 from opensourcerouting/ospf-topo1
Browse files Browse the repository at this point in the history
Basic OSPF(v2|v3) Topology
  • Loading branch information
mwinter-osr authored Jul 22, 2017
2 parents 535b887 + 69867fe commit 6706925
Show file tree
Hide file tree
Showing 34 changed files with 973 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/topogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def start(self):
if enabled == 0:
continue
self.vtysh_cmd('configure terminal\nlog file {}/{}-{}.log'.format(
self.logdir, self.name, daemon))
self.logdir, self.name, daemon), daemon=daemon)

return result

Expand All @@ -632,7 +632,7 @@ def stop(self):
self.logger.debug('stopping')
return self.tgen.net[self.name].stopRouter()

def vtysh_cmd(self, command, isjson=False):
def vtysh_cmd(self, command, isjson=False, daemon=None):
"""
Runs the provided command string in the vty shell and returns a string
with the response.
Expand All @@ -642,9 +642,14 @@ def vtysh_cmd(self, command, isjson=False):
"""
# Detect multi line commands
if command.find('\n') != -1:
return self.vtysh_multicmd(command)
return self.vtysh_multicmd(command, daemon=daemon)

dparam = ''
if daemon is not None:
dparam += '-d {}'.format(daemon)

vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command)

vtysh_command = 'vtysh -c "{}" 2>/dev/null'.format(command)
output = self.run(vtysh_command)
self.logger.info('\nvtysh command => {}\nvtysh output <= {}'.format(
command, output))
Expand All @@ -657,7 +662,7 @@ def vtysh_cmd(self, command, isjson=False):
logger.warning('vtysh_cmd: failed to convert json output')
return {}

def vtysh_multicmd(self, commands, pretty_output=True):
def vtysh_multicmd(self, commands, pretty_output=True, daemon=None):
"""
Runs the provided commands in the vty shell and return the result of
execution.
Expand All @@ -669,11 +674,15 @@ def vtysh_multicmd(self, commands, pretty_output=True):
# Prepare the temporary file that will hold the commands
fname = topotest.get_file(commands)

dparam = ''
if daemon is not None:
dparam += '-d {}'.format(daemon)

# Run the commands and delete the temporary file
if pretty_output:
vtysh_command = 'vtysh < {}'.format(fname)
vtysh_command = 'vtysh {} < {}'.format(dparam, fname)
else:
vtysh_command = 'vtysh -f {}'.format(fname)
vtysh_command = 'vtysh {} -f {}'.format(dparam, fname)

res = self.run(vtysh_command)
os.unlink(fname)
Expand Down
77 changes: 77 additions & 0 deletions lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,83 @@ def version_cmp(v1, v2):
return -1
return 0

def ip4_route(node):
"""
Gets a structured return of the command 'ip route'. It can be used in
conjuction with json_cmp() to provide accurate assert explanations.
Return example:
{
'10.0.1.0/24': {
'dev': 'eth0',
'via': '172.16.0.1',
'proto': '188',
},
'10.0.2.0/24': {
'dev': 'eth1',
'proto': 'kernel',
}
}
"""
output = normalize_text(node.run('ip route')).splitlines()
result = {}
for line in output:
columns = line.split(' ')
route = result[columns[0]] = {}
prev = None
for column in columns:
if prev == 'dev':
route['dev'] = column
if prev == 'via':
route['via'] = column
if prev == 'proto':
route['proto'] = column
if prev == 'metric':
route['metric'] = column
if prev == 'scope':
route['scope'] = column
prev = column

return result

def ip6_route(node):
"""
Gets a structured return of the command 'ip -6 route'. It can be used in
conjuction with json_cmp() to provide accurate assert explanations.
Return example:
{
'2001:db8:1::/64': {
'dev': 'eth0',
'proto': '188',
},
'2001:db8:2::/64': {
'dev': 'eth1',
'proto': 'kernel',
}
}
"""
output = normalize_text(node.run('ip -6 route')).splitlines()
result = {}
for line in output:
columns = line.split(' ')
route = result[columns[0]] = {}
prev = None
for column in columns:
if prev == 'dev':
route['dev'] = column
if prev == 'via':
route['via'] = column
if prev == 'proto':
route['proto'] = column
if prev == 'metric':
route['metric'] = column
if prev == 'pref':
route['pref'] = column
prev = column

return result

def checkAddressSanitizerError(output, router, component):
"Checks for AddressSanitizer in output. If found, then logs it and returns true, false otherwise"

Expand Down
Empty file added ospf-topo1/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions ospf-topo1/r1/ospf6d.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
router ospf6
router-id 10.0.255.1
redistribute kernel
redistribute connected
redistribute static
interface r1-eth0 area 0.0.0.0
interface r1-eth1 area 0.0.0.0
!
13 changes: 13 additions & 0 deletions ospf-topo1/r1/ospf6route.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*N IA 2001:db8:1::/64 :: r1-eth0 00:02:11
*N IA 2001:db8:2::/64 fe80::b038:bcff:fe27:e2d6 r1-eth1 00:02:06
N E1 2001:db8:2::/64 fe80::b038:bcff:fe27:e2d6 r1-eth1 00:02:06
*N IA 2001:db8:3::/64 :: r1-eth1 00:02:11
N E1 2001:db8:3::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:06
N E1 2001:db8:3::/64 fe80::b038:bcff:fe27:e2d6 r1-eth1 00:02:06
*N IA 2001:db8:100::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:06
N E1 2001:db8:100::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:06
*N IE 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:06
N E1 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:06
N E1 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:04
*N IE 2001:db8:300::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:04
N E1 2001:db8:300::/64 fe80::50b7:d8ff:fe5f:8ff0 r1-eth1 00:02:04
5 changes: 5 additions & 0 deletions ospf-topo1/r1/ospf6route_down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*N IA 2001:db8:1::/64 :: r1-eth0 00:01:51
*N IA 2001:db8:2::/64 fe80::281a:23ff:fe22:8a40 r1-eth1 00:00:52
N E1 2001:db8:2::/64 fe80::281a:23ff:fe22:8a40 r1-eth1 00:00:52
*N IA 2001:db8:3::/64 :: r1-eth1 00:00:52
N E1 2001:db8:3::/64 fe80::281a:23ff:fe22:8a40 r1-eth1 00:00:52
9 changes: 9 additions & 0 deletions ospf-topo1/r1/ospfd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
router ospf
ospf router-id 10.0.255.1
redistribute kernel
redistribute connected
redistribute static
network 10.0.1.0/24 area 0
network 10.0.3.0/24 area 0
!
23 changes: 23 additions & 0 deletions ospf-topo1/r1/ospfroute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
============ OSPF network routing table ============
N 10.0.1.0/24 [10] area: 0.0.0.0
directly attached to r1-eth0
N 10.0.2.0/24 [20] area: 0.0.0.0
via 10.0.3.3, r1-eth1
N 10.0.3.0/24 [10] area: 0.0.0.0
directly attached to r1-eth1
N 10.0.10.0/24 [20] area: 0.0.0.0
via 10.0.3.1, r1-eth1
N IA 172.16.0.0/24 [20] area: 0.0.0.0
via 10.0.3.1, r1-eth1
N IA 172.16.1.0/24 [30] area: 0.0.0.0
via 10.0.3.1, r1-eth1

============ OSPF router routing table =============
R 10.0.255.2 [10] area: 0.0.0.0, ASBR
via 10.0.3.3, r1-eth1
R 10.0.255.3 [10] area: 0.0.0.0, ABR, ASBR
via 10.0.3.1, r1-eth1
R 10.0.255.4 IA [20] area: 0.0.0.0, ASBR
via 10.0.3.1, r1-eth1

============ OSPF external routing table ===========
13 changes: 13 additions & 0 deletions ospf-topo1/r1/ospfroute_down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
============ OSPF network routing table ============
N 10.0.1.0/24 [10] area: 0.0.0.0
directly attached to r1-eth0
N 10.0.2.0/24 [20] area: 0.0.0.0
via 10.0.3.3, r1-eth1
N 10.0.3.0/24 [10] area: 0.0.0.0
directly attached to r1-eth1

============ OSPF router routing table =============
R 10.0.255.2 [10] area: 0.0.0.0, ASBR
via 10.0.3.3, r1-eth1

============ OSPF external routing table ===========
11 changes: 11 additions & 0 deletions ospf-topo1/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
!
interface r1-eth0
ip address 10.0.1.1/24
ipv6 address 2001:db8:1::1/64
!
interface r1-eth1
ip address 10.0.3.2/24
ipv6 address 2001:db8:3::2/64
!
ip forwarding
!
9 changes: 9 additions & 0 deletions ospf-topo1/r2/ospf6d.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
router ospf6
router-id 10.0.255.2
redistribute kernel
redistribute connected
redistribute static
interface r2-eth0 area 0.0.0.0
interface r2-eth1 area 0.0.0.0
!
13 changes: 13 additions & 0 deletions ospf-topo1/r2/ospf6route.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*N IA 2001:db8:1::/64 fe80::b49b:4cff:fe80:4e87 r2-eth1 00:03:34
N E1 2001:db8:1::/64 fe80::b49b:4cff:fe80:4e87 r2-eth1 00:03:34
*N IA 2001:db8:2::/64 :: r2-eth0 00:03:39
*N IA 2001:db8:3::/64 :: r2-eth1 00:03:34
N E1 2001:db8:3::/64 fe80::b49b:4cff:fe80:4e87 r2-eth1 00:03:34
N E1 2001:db8:3::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:34
*N IA 2001:db8:100::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:34
N E1 2001:db8:100::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:34
*N IE 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:34
N E1 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:34
N E1 2001:db8:200::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:32
*N IE 2001:db8:300::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:32
N E1 2001:db8:300::/64 fe80::50b7:d8ff:fe5f:8ff0 r2-eth1 00:03:32
5 changes: 5 additions & 0 deletions ospf-topo1/r2/ospf6route_down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*N IA 2001:db8:1::/64 fe80::fc0b:daff:fe31:6791 r2-eth1 00:06:19
N E1 2001:db8:1::/64 fe80::fc0b:daff:fe31:6791 r2-eth1 00:06:19
*N IA 2001:db8:2::/64 :: r2-eth0 00:07:17
*N IA 2001:db8:3::/64 :: r2-eth1 00:06:27
N E1 2001:db8:3::/64 fe80::fc0b:daff:fe31:6791 r2-eth1 00:06:19
9 changes: 9 additions & 0 deletions ospf-topo1/r2/ospfd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
router ospf
ospf router-id 10.0.255.2
redistribute kernel
redistribute connected
redistribute static
network 10.0.2.0/24 area 0
network 10.0.3.0/24 area 0
!
23 changes: 23 additions & 0 deletions ospf-topo1/r2/ospfroute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
============ OSPF network routing table ============
N 10.0.1.0/24 [20] area: 0.0.0.0
via 10.0.3.2, r2-eth1
N 10.0.2.0/24 [10] area: 0.0.0.0
directly attached to r2-eth0
N 10.0.3.0/24 [10] area: 0.0.0.0
directly attached to r2-eth1
N 10.0.10.0/24 [20] area: 0.0.0.0
via 10.0.3.1, r2-eth1
N IA 172.16.0.0/24 [20] area: 0.0.0.0
via 10.0.3.1, r2-eth1
N IA 172.16.1.0/24 [30] area: 0.0.0.0
via 10.0.3.1, r2-eth1

============ OSPF router routing table =============
R 10.0.255.1 [10] area: 0.0.0.0, ASBR
via 10.0.3.2, r2-eth1
R 10.0.255.3 [10] area: 0.0.0.0, ABR, ASBR
via 10.0.3.1, r2-eth1
R 10.0.255.4 IA [20] area: 0.0.0.0, ASBR
via 10.0.3.1, r2-eth1

============ OSPF external routing table ===========
13 changes: 13 additions & 0 deletions ospf-topo1/r2/ospfroute_down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
============ OSPF network routing table ============
N 10.0.1.0/24 [20] area: 0.0.0.0
via 10.0.3.2, r2-eth1
N 10.0.2.0/24 [10] area: 0.0.0.0
directly attached to r2-eth0
N 10.0.3.0/24 [10] area: 0.0.0.0
directly attached to r2-eth1

============ OSPF router routing table =============
R 10.0.255.1 [10] area: 0.0.0.0, ASBR
via 10.0.3.2, r2-eth1

============ OSPF external routing table ===========
11 changes: 11 additions & 0 deletions ospf-topo1/r2/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
!
interface r2-eth0
ip address 10.0.2.1/24
ipv6 address 2001:db8:2::1/64
!
interface r2-eth1
ip address 10.0.3.3/24
ipv6 address 2001:db8:3::3/64
!
ip forwarding
!
10 changes: 10 additions & 0 deletions ospf-topo1/r3/ospf6d.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!
router ospf6
router-id 10.0.255.3
redistribute kernel
redistribute connected
redistribute static
interface r3-eth0 area 0.0.0.0
interface r3-eth1 area 0.0.0.0
interface r3-eth2 area 0.0.0.1
!
12 changes: 12 additions & 0 deletions ospf-topo1/r3/ospf6route.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*N IA 2001:db8:1::/64 fe80::b49b:4cff:fe80:4e87 r3-eth0 00:04:03
N E1 2001:db8:1::/64 fe80::b49b:4cff:fe80:4e87 r3-eth0 00:04:03
*N IA 2001:db8:2::/64 fe80::b038:bcff:fe27:e2d6 r3-eth0 00:04:03
N E1 2001:db8:2::/64 fe80::b038:bcff:fe27:e2d6 r3-eth0 00:04:03
*N IA 2001:db8:3::/64 :: r3-eth0 00:04:08
N E1 2001:db8:3::/64 fe80::b49b:4cff:fe80:4e87 r3-eth0 00:04:03
N E1 2001:db8:3::/64 fe80::b038:bcff:fe27:e2d6 r3-eth0 00:04:03
*N IA 2001:db8:100::/64 :: r3-eth1 00:04:08
*N IA 2001:db8:200::/64 :: r3-eth2 00:04:05
N E1 2001:db8:200::/64 fe80::78e0:deff:feb1:ec0 r3-eth2 00:04:00
*N IA 2001:db8:300::/64 fe80::78e0:deff:feb1:ec0 r3-eth2 00:04:00
N E1 2001:db8:300::/64 fe80::78e0:deff:feb1:ec0 r3-eth2 00:04:00
5 changes: 5 additions & 0 deletions ospf-topo1/r3/ospf6route_down.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*N IA 2001:db8:100::/64 :: r3-eth1 00:08:06
*N IA 2001:db8:200::/64 :: r3-eth2 00:08:04
N E1 2001:db8:200::/64 fe80::80a6:c3ff:fea9:88be r3-eth2 00:07:59
*N IA 2001:db8:300::/64 fe80::80a6:c3ff:fea9:88be r3-eth2 00:07:59
N E1 2001:db8:300::/64 fe80::80a6:c3ff:fea9:88be r3-eth2 00:07:59
10 changes: 10 additions & 0 deletions ospf-topo1/r3/ospfd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!
router ospf
ospf router-id 10.0.255.3
redistribute kernel
redistribute connected
redistribute static
network 10.0.3.0/24 area 0
network 10.0.10.0/24 area 0
network 172.16.0.0/24 area 1
!
23 changes: 23 additions & 0 deletions ospf-topo1/r3/ospfroute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
============ OSPF network routing table ============
N 10.0.1.0/24 [20] area: 0.0.0.0
via 10.0.3.2, r3-eth0
N 10.0.2.0/24 [20] area: 0.0.0.0
via 10.0.3.3, r3-eth0
N 10.0.3.0/24 [10] area: 0.0.0.0
directly attached to r3-eth0
N 10.0.10.0/24 [10] area: 0.0.0.0
directly attached to r3-eth1
N 172.16.0.0/24 [10] area: 0.0.0.1
directly attached to r3-eth2
N 172.16.1.0/24 [20] area: 0.0.0.1
via 172.16.0.1, r3-eth2

============ OSPF router routing table =============
R 10.0.255.1 [10] area: 0.0.0.0, ASBR
via 10.0.3.2, r3-eth0
R 10.0.255.2 [10] area: 0.0.0.0, ASBR
via 10.0.3.3, r3-eth0
R 10.0.255.4 [10] area: 0.0.0.1, ASBR
via 172.16.0.1, r3-eth2

============ OSPF external routing table ===========
Loading

0 comments on commit 6706925

Please sign in to comment.