Add support for connecting to the FRR daemon shells

This commit is contained in:
Wojciech Kozlowski 2019-04-07 13:05:30 +02:00
parent 71bc827fb2
commit 5482b89128
16 changed files with 125 additions and 19 deletions

View File

@ -73,6 +73,22 @@ experiment with the following command.
sudo python route-0.py --topology <topology_name> --scenario <scenario_name> sudo python route-0.py --topology <topology_name> --scenario <scenario_name>
``` ```
### Connecting to an FRR daemon
To connect to an FRR daamon, you can either run the following command inside
the Mininet CLI
```
<node_name> telnet localhost <daemon_name>
```
You can also connect to an FRR daemon from a different terminal than the one in
which the Mininet CLI is running. To do this run
```
sudo python attach.py --node <node_name> --daemon <daemon_name>
```
The password for all daemons is `route0`.
### Lessons ### Lessons
TODO: WRITE UP LESSONS TODO: WRITE UP LESSONS
@ -106,6 +122,18 @@ in Mininet the destination can also be specified using its name. It is
possible to do so in Route 0, but this is often ambiguous as routers will have possible to do so in Route 0, but this is often ambiguous as routers will have
multiple IP addresses associated with their interfaces. multiple IP addresses associated with their interfaces.
It is also possible to launch a shell or run a command in a Mininet node from a
different terminal than the one in which the Mininet CLI is being run. A
convenience script has been provided for this purpose, `attach.py`. To launch
a shell in a particular node run
```
sudo python attach.py --node <node_name>
```
You can also directly specify the daemon to connect to with `--daemon` or a
shell command to run with `--cmd`.
The password for all daemons is `route0`.
## FRR Concepts ## FRR Concepts
This section will introduce some basic FRR concepts that are in particular This section will introduce some basic FRR concepts that are in particular
@ -121,10 +149,8 @@ routes as appropriate.
FRR routing protocols are configured using configuration files. The details of FRR routing protocols are configured using configuration files. The details of
how to write these configurations are on the [FRR documentation how to write these configurations are on the [FRR documentation
website](http://docs.frrouting.org/en/latest/). It is also possible to connect website](http://docs.frrouting.org/en/latest/). It is also possible to connect
to running instances of the protocols. However, this is not currently to running instances of the protocols. See the Mininet and Getting Started
supported in Route 0. sections on how this can be done.
TODO: ADD SUPPORT TO CONNECT TO ROUTING PROTOCOL SHELL
## Structure ## Structure

52
attach.py Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env python
import argparse
import os
from subprocess import Popen, PIPE
import re
def get_pid(node_name):
"""Get the system process ID for the node.
"""
node_pat = re.compile('.*bash .* mininet:{}'.format(node_name))
out, _ = Popen("ps aux".split(), stdout=PIPE).communicate()
for line in out.split('\n'):
match = node_pat.match(line)
if not match:
continue
pid = line.split()[1]
return pid
raise KeyError("No process found for {}".format(node_name))
def main():
"""Entry point for attach.
"""
parser = argparse.ArgumentParser("Connect to a mininet node.")
parser.add_argument('-n', '--node',
required=True,
help="The node's name (e.g., h1_1, R1, etc.)")
parser.add_argument('-d', '--daemon',
help="Connect directly to this FRR daemon.")
parser.add_argument('-c', '--cmd',
default=["sh"],
nargs="+",
help="Command to run on the node."
" Default is to start sh.")
args = parser.parse_args()
pid = get_pid(args.node)
cmd = ' '.join(args.cmd)
if args.daemon is not None:
cmd = "telnet localhost {}".format(args.daemon)
os.system("mnexec -a {} {}".format(pid, cmd))
if __name__ == '__main__':
main()

View File

@ -80,9 +80,9 @@ def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Launch an FRR network experiment in Mininet.') description='Launch an FRR network experiment in Mininet.')
parser.add_argument('--topology', '-t', type=str, required=True, parser.add_argument('-t', '--topology', required=True,
help='the topology of the network') help='the topology of the network')
parser.add_argument('--scenario', '-s', type=str, required=True, parser.add_argument('-s', '--scenario', required=True,
help='the scenario to set up in the network') help='the scenario to set up in the network')
args = parser.parse_args() args = parser.parse_args()

View File

@ -1,6 +1,8 @@
! -*- staticd -*- ! -*- staticd -*-
hostname h1_1 hostname h1_1-staticd
password route0
enable password route0
ip route 0.0.0.0/0 10.1.0.254 ip route 0.0.0.0/0 10.1.0.254

View File

@ -1,6 +1,8 @@
! -*- staticd -*- ! -*- staticd -*-
hostname h2_1 hostname h2_1-staticd
password route0
enable password route0
ip route 0.0.0.0/0 10.2.0.254 ip route 0.0.0.0/0 10.2.0.254

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname R1 hostname R1-zebra
password route0
enable password route0
interface lo interface lo
ip address 10.0.0.1/32 ip address 10.0.0.1/32

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname h1_1 hostname h1_1-zebra
password route0
enable password route0
interface h1_1-eth1 interface h1_1-eth1
ip address 10.1.0.1/24 ip address 10.1.0.1/24

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname h2_1 hostname h2_1-zebra
password route0
enable password route0
interface h2_1-eth1 interface h2_1-eth1
ip address 10.2.0.1/24 ip address 10.2.0.1/24

View File

@ -1,9 +1,12 @@
! -*- isisd -*- ! -*- isisd -*-
hostname R1 hostname R1-isisd
password route0
enable password route0
router isis ROUTE0 router isis ROUTE0
net 49.0001.0000.0000.0001.00 net 49.0001.0000.0000.0001.00
is-type level-2-only
interface lo interface lo
ip router isis ROUTE0 ip router isis ROUTE0

View File

@ -1,9 +1,12 @@
! -*- isisd -*- ! -*- isisd -*-
hostname R2 hostname R2-isisd
password route0
enable password route0
router isis ROUTE0 router isis ROUTE0
net 49.0002.0000.0000.0002.00 net 49.0002.0000.0000.0002.00
is-type level-2-only
interface lo interface lo
ip router isis ROUTE0 ip router isis ROUTE0

View File

@ -1,6 +1,8 @@
! -*- staticd -*- ! -*- staticd -*-
hostname h1_1 hostname h1_1-staticd
password route0
enable password route0
ip route 0.0.0.0/0 10.1.0.254 ip route 0.0.0.0/0 10.1.0.254

View File

@ -1,6 +1,8 @@
! -*- staticd -*- ! -*- staticd -*-
hostname h2_1 hostname h2_1-staticd
password route0
enable password route0
ip route 0.0.0.0/0 10.2.0.254 ip route 0.0.0.0/0 10.2.0.254

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname R1 hostname R1-zebra
password route0
enable password route0
interface lo interface lo
ip address 10.0.0.1/32 ip address 10.0.0.1/32

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname R2 hostname R2-zebra
password route0
enable password route0
interface lo interface lo
ip address 10.0.0.2/32 ip address 10.0.0.2/32

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname h1_1 hostname h1_1-zebra
password route0
enable password route0
interface h1_1-eth1 interface h1_1-eth1
ip address 10.1.0.1/24 ip address 10.1.0.1/24

View File

@ -1,6 +1,8 @@
! -*- zebra -*- ! -*- zebra -*-
hostname h2_1 hostname h2_1-zebra
password route0
enable password route0
interface h2_1-eth1 interface h2_1-eth1
ip address 10.2.0.1/24 ip address 10.2.0.1/24