practical sheet

Upload: thilini

Post on 01-Mar-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Practical Sheet

    1/20

    Practical Sheet 1

    Mininet Setup

    Goal

    The goal of this assignment is to setup the Mininet virtual machine on the computer you will use

    for course assignments. Preferably this computer will be the machine with the most memory and

    fastest processor if you have multiple computers as some assignments will take a few minutes to

    run.

    Directions

    1.Download and install the latest Virtualbox for your platform. You can find Virtualboxhere.

    2.Download the latest Mininet virtual machine imagehere (64bit).The download is ~1GB in

    size so be patient with the download and if possible, connect your computer to the

    Internet via a wired connection. If the download is especially slow, setup your computer to

    download the image overnight.

    3.In Virtualbox selectFile -> Import Applianceand select the .ovayou just downloaded.

    Virtualbox will show you the VM settings and you can then click Import.

    4.Next, setup a bridged network by selecting the VM in the left side bar and thenSettings

    -> Networkand ensure thatAdapter 1is enabled and attached to aBridged Adapter.

    https://www.virtualbox.org/wiki/Downloadshttps://www.virtualbox.org/wiki/Downloadshttps://www.virtualbox.org/wiki/Downloadshttp://content.udacity-data.com/courses/gt-cs6250/mininet-pyretic-vm.ovahttp://content.udacity-data.com/courses/gt-cs6250/mininet-pyretic-vm.ovahttp://content.udacity-data.com/courses/gt-cs6250/mininet-pyretic-vm.ovahttps://www.virtualbox.org/wiki/Downloads
  • 7/25/2019 Practical Sheet

    2/20

    Once youve ensured this, close the settings dialog.

    5.Start the VM by clickingStart.

    6.Log in to the VM usingmininetfor the username and password.

    7.Typesudo ifcongon command line. This will display the IP addresses of the connected

    network interfaces. Note if you have trouble with this step try the instructions under

    "Setup Network Access"here.

    8.Open a terminal on your desktop (Terminal on Mac OSX, Putty on Windows and xterm on

    Linux) and typess mininet!ip"addresswhere ip_address is the IP address under

    theet#output from the ifconfig command. Use the passwordmininet.

    9.Now we will run a test to ensure Mininet is working correctly. Typesudo mn --test

    pingpair.

    https://docs.google.com/document/d/1G0tHNj64-Gl0fjYDUdR5COIr9PhKg-a14l2LVnsH_EE/edithttps://docs.google.com/document/d/1G0tHNj64-Gl0fjYDUdR5COIr9PhKg-a14l2LVnsH_EE/edithttps://docs.google.com/document/d/1G0tHNj64-Gl0fjYDUdR5COIr9PhKg-a14l2LVnsH_EE/edit
  • 7/25/2019 Practical Sheet

    3/20

    Exercise 1

    Everyday Mininet Usage

    First, a (perhaps obvious) note on command syntax for this walkthrough

    $preceeds $inu% commands tat sould &e t'ped at te sell prompt

    mininet>preceeds (ininet commands tat sould &e t'ped at (ininet)s

    *$I+

    #preceeds $inu% commands tat are t'ped at a root sell prompt

    In each case, you should only type the command to the right of the prompt (and

    then press return, of course!)

    !isplay "tartup #ptions

    $et%s get started with Mininet%s startup options&

    'ype the following command to display a help message describing Mininet%s startup options

    $ sudo mn -h

    'his walkthrough will cover typical usage of the maority of options listed&

    "tart ireshark

    'o view control traffic using the #penFlow ireshark dissector, first open wireshark in the

    background

    $ sudo wireshark &

    *n the ireshark filter box, enter this filter, then click Apply

    of

    *n ireshark, click +apture, then *nterfaces, then select "tart on the loopback interface (lo)&

    For now, there should be no #penFlow packets displayed in the main window&

  • 7/25/2019 Practical Sheet

    4/20

    Note: Wireshark is installed by default in the Mininet VM image If the system

    you are using does not hae Wireshark and the "pen#lo$ plugin installed, you

    may be able to install both of them using Mininet%s install.shscript as follo$s:

    $ cd ~

    $ git clone https://github.com/mininet/mininet # if it's not already there

    $ mininet/util/install.sh -w

    *f ireshark is installed but you cannot run it (e&g& you get an error like $DISPLAY not set,

    please consult the F- ttps,gitu&.commininetmininetwikiFA/wiki-%11-

    forwarding&)

    "etting .// up correctly will enable you to run other 0U* programs and the xtermterminalemulator, used later in this walkthrough&

    *nteract with 1osts and "witches

    "tart a minimal topology and enter the +$*

    $ sudo mn

    'he default topology is the minimaltopology, which includes one #penFlow kernel switch

    connected to two hosts, plus the #penFlow reference controller& 'his topology could also be

    specified on the command line with --topo=minimal& #ther topologies are also available out

    of the box2 see the --toposection in the output of mn -h&

    ll four entities (3 host processes, / switch process, / basic controller) are now running in

    the 4M& 'he controller can be outside the 4M, and instructions for that are at the bottom&

    *f no specific test is passed as a parameter, the Mininet +$* comes up&

    *n the ireshark window, you should see the kernel switch connect to the reference

    controller&

    !isplay Mininet +$* commands

    mininet> help

    !isplay nodes

    https://github.com/mininet/mininet/wiki/FAQ#wiki-x11-forwardinghttps://github.com/mininet/mininet/wiki/FAQ#wiki-x11-forwardinghttps://github.com/mininet/mininet/wiki/FAQ#wiki-x11-forwardinghttps://github.com/mininet/mininet/wiki/FAQ#wiki-x11-forwardinghttps://github.com/mininet/mininet/wiki/FAQ#wiki-x11-forwarding
  • 7/25/2019 Practical Sheet

    5/20

    mininet> nodes

    !isplay links

    mininet> net

    !ump information about all nodes

    mininet> dump

    5ou should see the switch and two hosts listed&

    *f the first string typed into the Mininet +$* is a host, switch or controller name, the command

    is executed on that node& 6un a command on a host process

    mininet> h1 ifconfig -a

    5ou should see the host%s h1-eth0and loopback (lo) interfaces& 7ote that this interface (h1-

    eth0) is not seen by the primary $inux system when ifconfigis run, because it is specific to

    the network namespace of the host process&

    *n contrast, the switch by default runs in the root network namespace, so running a

    command on the 8switch9 is the same as running it from a regular terminal

    mininet> s1 ifconfig -a

    'his will show the switch interfaces, plus the 4M%s connection out (eth0)&

    For other examples highlighting that the hosts have isolated network state,

    run arpand routeon both s1and h1&

    *t would be possible to place every host, switch and controller in its own isolated network

    namespace, but there%s no real advantage to doing so, unless you want to replicate a

    complex multiple:controller network& Mininet does support this2 see the--innamespaceoption&

    7ote that onlythe network is virtuali;ed2 each host process sees the same set of processes

    and directories& For example, print the process list from a host process

  • 7/25/2019 Practical Sheet

    6/20

    mininet> h1 ps -a

    'his should be the exact same as that seen by the root network namespace

    mininet> s1 ps -a

    *t would be possible to use separate process spaces with $inux containers, but currently

    Mininet doesn%t do that& 1aving everything run in the 8root9 process namespace is

    convenient for debugging, because it allows you to see all of the processes from the console

    using ps, kill, etc&

    'est connectivity between hosts

    7ow, verify that you can ping from host < to host /

    mininet> h1 ping -c 1 h2

    *f a string appears later in the command with a node name, that node name is replaced by

    its *= address2 this happened for h3&

    5ou should see #penFlow control traffic& 'he first host 6=s for the M+ address of the

    second, which causes a packet_inmessage to go to the controller& 'he controller then

    sends a packet_outmessage to flood the broadcast packet to other ports on the switch (in

    this example, the only other data port)& 'he second host sees the 6= re>uest and sends a

    reply& 'his reply goes to the controller, which sends it to the first host and pushes down a

    flow entry&

    7ow the first host knows the M+ address of the second, and can send its ping via an *+M=

    Echo 6e>uest& 'his re>uest, along with its corresponding reply from the second host, bothgo the controller and result in a flow entry pushed down (along with the actual packets

    getting sent out)&

    6epeat the last ping

    mininet> h1 ping -c 1 h2

  • 7/25/2019 Practical Sheet

    7/20

    5ou should see a much lower pingtime for the second try (? /uest from h2, then shutting down

    the web server

    mininet> h1 python -m SimpleHTTPServer 80 &

    mininet> h2 wget -O - h1

    ...

    mininet> h1 kill %python

    Exit the +$*

    mininet> exit

    +leanup

    *f Mininet crashes for some reason, clean it up

    $ sudo mn -c

    +reating a 7etwork

    5ou can create a network with a single command& For example,

  • 7/25/2019 Practical Sheet

    8/20

    sudo mn --switch ovs --controller ref --topo tree,depth=2,fanout=8 --test

    pingall

    starts a network with a tree topology of depth 3 and fanout A (i&e& BC hosts connected to D

    switches), using #pen v"witch switches under the control of the #penFlow"tanford

    reference controller, and runs the pingalltest to check connectivity between every pair of

    nodes& ('his takes about C seconds on my laptop&)

    *nteracting with a 7etwork

    Mininet%s +$* allows you to control, and manage your entire virtual network from a single

    console& For example, the +$* command

    mininet> h2 ping h3

    tells host h2to ping host h2 %s *= address&&ny aailable 'inu command or program

    can be run on any irtual host& 5ou can easily start a web server on one host and make

    an 1''= re>uest from another

    mininet> h2 python -m SimpleHTTPServer 80 >& /tmp/http.log &

    mininet> h3 wget -O - h2

    +ustomi;ing a 7etwork

    Mininet%s =* allows you to create custom networks with a few lines of =ython& For example,

    the following script

    1

    2

    3

    4

    5

    6

    7

    8

    from mininet.net import Mininet

    from mininet.topolib import TreeTopo

    tree4 = TreeTopo(depth=2f!no"t=2#

    net = Mininet(topo=tree4#

    net.st!rt(#

    h1 h4 = net.hosts$%& net.hosts$3&

    print h1.cmd('pin )c1 *s' * h4.+,(##

    net.stop(#

    creates a small network (C hosts, G switches), and pings one host from another (in about Cseconds with the current version&)

  • 7/25/2019 Practical Sheet

    9/20

    'he Mininet distribution includes several text:based and graphical (see above) applications

    which we hope will be instructive and inspire you to create cool and useful apps for your own

    network designs&

    "haring a 7etwork

    Mininet is distributed as a virtual machine (4M) image with all dependencies pre:installed,

    runnable on common virtual machine monitors such as 4Mware, .en and 4irtualHox& 'his

    provides a convenient container for distribution2 once a prototype has been developed, the

    4M image may be distributed to others to run, examine and modify& complete, compressed

    Mininet 4M is about /0H& (Mininet can also be installed natively : apt-get install

    minineton Ubuntu&) *f you are reading a great "*0+#MM (or other) paper about a

    "oftware:!efined 7etwork, wouldn%t you like to be able to click, download and run a living,

    breathing example of the systemI *f so, consider developing a Mininet version of your ownsystem that you can share with others@

    6unning on 1ardware

    #nce a design works on Mininet, it can be deployed on hardware for real:world use, testing

    and measurement&

    'o successfully port to hardware on the first try, every Mininet:emulated component must act

    in the same way as its corresponding physical one& 'he virtual topology should match the

    physical one2 virtual Ethernet pairs must be replaced by link:level Ethernet connectivity&

    1osts emulated as processes should be replaced by hosts with their own #" image& *n

    addition, each emulated #penFlow switch should be replaced by a physical one configured

    to point to the controller& 1owever, the controller does not need to change& hen Mininet is

    running, the controller 8sees9 a physical network of switches, made possible by an interface

    with well:defined state semantics&

    6un a 6egression 'est

    5ou don%t need to drop into the +$*2 Mininet can also be used to run self:contained

    regression tests&

    6un a regression test

    $ sudo mn --test pingpair

    'his command created a minimal topology, started up the #penFlow reference controller,

    ran an all:pairs:pingtest, and tore down both the topology and the controller&

  • 7/25/2019 Practical Sheet

    10/20

    nother useful test is iperf(give it about /< seconds to complete)

    $ sudo mn --test iperf

    'his command created the same Mininet, ran an iperf server on one host, ran an iperf client

    on the second host, and parsed the bandwidth achieved&

    +hanging 'opology "i;e and 'ype

    'he default topology is a single switch connected to two hosts& 5ou could change this to a

    different topo with --topo, and pass parameters for that topology%s creation& For example, to

    verify all:pairs ping connectivity with one switch and three hosts

    6un a regression test

    $ sudo mn --test pingall --topo single,3

    nother example, with a linear topology (where each switch has one host, and all switches

    connect in a line)

    $ sudo mn --test pingall --topo linear,4

    =arametri;ed topologies are one of Mininet%s most useful and powerful features&

    $ink variations

    Mininet 3&< allows you to set link parameters, and these can even be set automatially from

    the command line

    $ sudo mn --link tc,bw=10,delay=10ms

    mininet> iperf

    ...

    mininet> h1 ping -c10 h2

    *f the delay for each link is /< ms, the round trip time (6'') should be about C< ms, since the

    *+M= re>uest traverses two links (one to the switch, one to the destination) and the *+M=

    reply traverses two links coming back&

  • 7/25/2019 Practical Sheet

    11/20

    ou can customi*e each link using Mininet%s +ython &+I, but for no$ you $ill

    probably $ant to continue $ith the $alkthrough

    dustable 4erbosity

    'he default verbosity level is info, which prints what Mininet is doing during startup and

    teardown& +ompare this with the full debugoutput with the -vparam

    $ sudo mn -v debug

    ...

    mininet> exit

    $ots of extra detail will print out& 7ow try output, a setting that prints +$* output and littleelse

    $ sudo mn -v output

    mininet> exit

    #utside the +$*, other verbosity levels can be used, such as warning, which is used with the

    regression tests to hide unneeded function output&

    +ustom 'opologies

    +ustom topologies can be easily defined as well, using a simple =ython =*, and an

    example is provided in custom/topo-2sw-2host.py& 'his example connects two switches

    directly, with a single host off each switch

    simple topolog' e%ample 0topo-sw-ost.p'2download

    1

    2

    3

    4

    5

    6

    7

    8

    -

    1%

    /"stom topolo0 ex!mple

    To directl0 connected sitches pl"s ! host for e!ch sitch

    host ))) sitch ))) sitch ))) host

    ddin the 'topos' dict ith ! e0!l"e p!ir to ener!te o"r nel0 dened

    topolo0 en!bles one to p!ss in '))topo=m0topo' from the comm!nd line.

    from mininet.topo import Topo

    https://github.com/mininet/mininet/wiki/Introduction-to-Mininethttp://mininet.org/mininet/custom/topo-2sw-2host.pyhttps://github.com/mininet/mininet/wiki/Introduction-to-Mininethttp://mininet.org/mininet/custom/topo-2sw-2host.py
  • 7/25/2019 Practical Sheet

    12/20

    1

    1

    1

    2

    1

    3

    1

    4

    1

    5

    1

    6

    17

    1

    8

    1

    -

    2

    %

    2

    1

    2

    2

    2

    3

    2

    4

    2

    5

    2

    6

    2

    7

    2

    8

    2

    -

    3

    %

    cl!ss M0Topo( Topo #

    imple topolo0 ex!mple.

    def 99init99( self #

    /re!te c"stom topo.

    : +niti!li;e topolo0

    Topo.99init99( self #

    : dd hosts !nd sitches

    left

  • 7/25/2019 Practical Sheet

    13/20

    3

    1

    3

    2

    3

    3

    3

    4

    hen a custom mininet file is provided, it can add new topologies, switch types, and tests to

    the command:line& For example

    $ sudo mn --custom ~/mininet/custom/topo-2sw-2host.py --topo mytopo --test

    pingall

    *! J M+

    Hy default, hosts start with randomly assigned M+ addresses& 'his can make debugging

    tough, because every time the Mininet is created, the M+s change, so correlating control

    traffic with specific hosts is tough&

    'he --macoption is super:useful, and sets the host M+ and *= addrs to small, uni>ue,

    easy:to:read *!s&

    Hefore

    $ sudo mn

    ...

    mininet> h1 ifconfig

    h1-eth0 Link encap:Ethernet HWaddr f6:9d:5a:7f:41:42

    inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:6 errors:0 dropped:0 overruns:0 frame:0

    TX packets:6 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:392 (392.0 B) TX bytes:392 (392.0 B)

    mininet> exit

    fter

  • 7/25/2019 Practical Sheet

    14/20

    $ sudo mn --mac

    ...

    mininet> h1 ifconfig

    h1-eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:01

    inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:0 errors:0 dropped:0 overruns:0 frame:0

    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

    mininet> exit

    In contrast, the M&s for s$itch data ports reported by 'inu $ill remain

    random -his is because you can .assign% a M& to a data port using "pen#lo$,

    as noted in the #&/ -his is a some$hat subtle point $hich you can probably

    ignore for no$

    .'erm !isplay

    For more complex debugging, you can start Mininet so that it spawns one or more xterms&

    'o start an xtermfor every host and switch, pass the -xoption

    $ sudo mn -x

    fter a second, the xterms will pop up, with automatically set window names&

    lternately, you can bring up additional xterms as shown below&

    Hy default, only the hosts are put in a separate namespace2 the window for each switch is

    unnecessary (that is, e>uivalent to a regular terminal), but can be a convenient place to run

    and leave up switch debug commands, such as flow counter dumps&

    .terms are also useful for running interactive commands that you may need to cancel, for

    which you%d like to see the output&

    For example

    *n the xterm labeled 8switch s/ (root)9, run

  • 7/25/2019 Practical Sheet

    15/20

    # dpctl dump-flows tcp:127.0.0.1:6634

    7othing will print out2 the switch has no flows added& 'o use dpctlwith other switches, start

    up mininet in verbose mode and look at the passive listening ports for the switches when

    they%re created&

    7ow, in the xterm labeled 8host h/9, run

    # ping 10.0.0.2

    0o back to s1and dump the flows K dpctl dump:flows tcp/3L&

  • 7/25/2019 Practical Sheet

    16/20

    variable, as the user:space process representing the host may be scheduled in and out by

    the #"&

    #n the other hand, the user:space switch can be a great starting point for implementing new

    functionality, especially where software performance is not critical&

    nother example switch type is #pen v"witch (#4"), which comes preinstalled on the

    Mininet 4M& 'he iperf:reported '+= bandwidth should be similar to the #penFlow kernel

    module, and possibly faster

    $ sudo mn --switch ovsk --test iperf

    Mininet Henchmark

    'o record the time to set up and tear down a topology, use test none%

    $ sudo mn --test none

    Everything in its own 7amespace (user switch only)

    Hy default, the hosts are put in their own namespace, while switches and the controller are in

    the root namespace& 'o put switches in their own namespace, pass the --

    innamespaceoption

    $ sudo mn --innamespace --switch user

    *nstead of using loopback, the switches will talk to the controller through a separately

    bridged control connection& Hy itself, this option is not terribly useful, but it does provide an

    example of how to isolate different switches&

    7ote that this option does not (as of ///D/3) work with #pen v"witch&

    mininet> exit

    Mininet +ommand:$ine *nterface (+$*) +ommands

    !isplay #ptions

    'o see the list of +ommand:$ine *nterface (+$*) options, start up a minimal topology andleave it running& Huild the Mininet

  • 7/25/2019 Practical Sheet

    17/20

    $ sudo mn

    !isplay the options

    mininet> help

    =ython *nterpreter

    *f the first phrase on the Mininiet command line is py, then that command is executed with

    =ython& 'his might be useful for extending Mininet, as well as probing its inner workings&

    Each host, switch, and controller has an associated 7ode obect&

    t the Mininet +$*, run

    mininet> py 'hello ' + 'world'

    =rint the accessible local variables

    mininet> py locals()

    7ext, see the methods and properties available for a node, using the dir() function

    mininet> py dir(s1)

    5ou can read the on:line documentation for methods available on a node by using the help()

    function

    mininet> py help(h1) (Press "q" to quit reading the documentation.)

    5ou can also evaluate methods of variables

    mininet> py h1.IP()

    $ink Up!own

    For fault tolerance testing, it can be helpful to bring links up and down&

  • 7/25/2019 Practical Sheet

    18/20

    'o disable both halves of a virtual ethernet pair

    mininet> link s1 h1 down

    5ou should see an #penFlow =ort "tatus +hange notification get generated& 'o bring the

    link back up

    mininet> link s1 h1 up

    .'erm !isplay

    'o display an xterm for h/ and h3

    mininet> xterm h1 h2

    Exercise 2

    /3usr&inp'ton

    444

    *reate a network and start ssd052 on eac ost.

    6ile someting like rsd052 would &e ligter and faster+

    0and perfectl' ade7uate on an in-macine network2

    te advantage of running ssd is tat scripts can work

    uncanged on mininet and ardware.

    In addition to providing ss access to osts+ tis e%ample

    demonstrates,

    - creating a convenience function to construct networks- connecting te ost network to te root namespace

    - running server processes 0ssd in tis case2 on osts

    444

    nserimports's

    frommininet.net import(ininet

    frommininet.cli import*$I

    frommininet.log importlg

    frommininet.node importNode

  • 7/25/2019 Practical Sheet

    19/20

    frommininet.topoli& import8ree8opo

    frommininet.util importwait$istening

    def8reeNet0 dept91+ fanout9+ ::kwargs 2,

    4*onvenience function for creating tree networks.4

    topo 98ree8opo0 dept+ fanout 2

    return(ininet0 topo+ ::kwargs 2

    defconnect8o;ootNS0 network+ switc+ ip+ routes 2,

    444*onnect osts to root namespace via switc. Starts network.

    network, (ininet02 network o&

  • 7/25/2019 Practical Sheet

    20/20

    print

    print4::: 8'pe e%it or control-@ to sut down network4

    *$I0 network 2

    forost innetwork.osts,

    ost.cmd0 kill H?cmd 2

    network.stop02

    if""name""99""main"",

    lg.set$og$evel0 info2

    net 98reeNet0 dept91+ fanout92

    / get ssd args from te command line or use default args

    / use@NS9no -u# to avoid reverse @NS lookup timeout

    argvopts 9 .1else0

    -@ -o se@NS9no -u#2

    ssd0 net+ opts9argvopts 2