Question

In this assignment you will start with Python code that builds a 2 host network connected...

In this assignment you will start with Python code that builds a 2 host network connected by a legacy router. You will modify it such that the two hosts can send packets to each other. It requires that you understand subnet addressing and the function of a router. The network built using Miniedit on a Mininet virtual machine: python mininet/examples/miniedit.py

The code generated by exporting it as a Level 2 Script: (unused imports and code added by Miniedit have been removed):

#!/usr/bin/python

# File: legacy_router.py

from mininet.net

import Mininet from mininet.node

import Host, Node from mininet.cli

import CLI from mininet.log

import setLogLevel, info

def myNetwork():

net = Mininet( topo=None,

   build=False,

   ipBase='10.0.0.0/8')

info( '*** Adding controller\n' )

info( '*** Add switches\n')

r1 = net.addHost('r1', cls=Node, ip='0.0.0.0')

r1.cmd('sysctl -w net.ipv4.ip_forward=1')

info( '*** Add hosts\n')

h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)

h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)


info( '*** Add links\n')

net.addLink(h1, r1)

net.addLink(h2, r1)

info( '*** Starting network\n')

net.build()

CLI(net)

   net.stop()

if __name__ == '__main__':

setLogLevel( 'info' )
myNetwork()

Executing this code and trying a ping results in “Destination Host Unreachable”:

mininet@mininet-vm:~$ sudo python legacy_router.py

*** Adding controller

*** Add switches

*** Add hosts

*** Add links

*** Starting network

*** Configuring hosts

r1 h2 h1

*** Starting CLI: mininet> h1 ping h2

PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.

From 10.0.0.1 icmp_seq=1 Destination Host Unreachable

From 10.0.0.1 icmp_seq=2 Destination Host Unreachable

From 10.0.0.1 icmp_seq=3 Destination Host Unreachable

Your task is to modify this program (perhaps using different IP addresses) such that the legacy router is able to forward packets between the two hosts. You will need to understand Internet addressing, subnets, and the function of a router as described in the “IPv4 Addressing” Section of Kurose and Ross (4.3.3 in 7th Edition, 4.4.2 in 6th Edition). You may also find the example Python programs in mininet/examples helpful; in particular linuxrouter.py . I suggest executing that program and studying it to understand how you will need to modify legacy_router.py.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Try this one

#!/usr/bin/python

"""
Create a network with 5 hosts, numbered 1-4 and 9.
Validate that the port numbers match to the interface name,
and that the ovs ports match the mininet ports.
"""


from mininet.net import Mininet
from mininet.node import Controller
from mininet.log import setLogLevel, info, warn

def validatePort( switch, intf ):
    "Validate intf's OF port number"
    ofport = int( switch.cmd( 'ovs-vsctl get Interface', intf,
                              'ofport' ) )
    if ofport != switch.ports[ intf ]:
        warn( 'WARNING: ofport for', intf, 'is actually', ofport, '\n' )
        return 0
    else:
        return 1

def testPortNumbering():

    """Test port numbering:
       Create a network with 5 hosts (using Mininet's
       mid-level API) and check that implicit and
       explicit port numbering works as expected."""

    net = Mininet( controller=Controller )

    info( '*** Adding controller\n' )
    net.addController( 'c0' )

    info( '*** Adding hosts\n' )
    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )
    h5 = net.addHost( 'h5', ip='10.0.0.5' )

    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1' )

    info( '*** Creating links\n' )
    # host 1-4 connect to ports 1-4 on the switch
    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )
    net.addLink( h4, s1 )
    # specify a different port to connect host 5 to on the switch.
    net.addLink( h5, s1, port1=1, port2= 9)

    info( '*** Starting network\n' )
    net.start()

    # print the interfaces and their port numbers
    info( '\n*** printing and validating the ports '
          'running on each interface\n' )
    for intfs in s1.intfList():
        if not intfs.name == "lo":
            info( intfs, ': ', s1.ports[intfs],
                  '\n' )
            info( 'Validating that', intfs,
                   'is actually on port', s1.ports[intfs], '... ' )
            if validatePort( s1, intfs ):
                info( 'Validated.\n' )
    info( '\n' )

    # test the network with pingall
    net.pingAll()
    info( '\n' )

    info( '*** Stopping network\n' )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
testPortNumbering()

Or else this one

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.nodelib import LinuxBridge #OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call

def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    info( '*** Add switches\n')
    r7 = net.addHost('r7', cls=Node, ip='0.0.0.0')
    r7.cmd('sysctl -w net.ipv4.ip_forward=1')
    s2 = net.addSwitch('s2', cls=LinuxBridge, failMode='standalone', stp=1)
    s4 = net.addSwitch('s4', cls=LinuxBridge, failMode='standalone', stp=1)
    r8 = net.addHost('r8', cls=Node, ip='0.0.0.0')
    r8.cmd('sysctl -w net.ipv4.ip_forward=1')
    s1 = net.addSwitch('s1', cls=LinuxBridge, failMode='standalone', stp=1)
    r6 = net.addHost('r6', cls=Node, ip='0.0.0.0')
    r6.cmd('sysctl -w net.ipv4.ip_forward=1')
    s3 = net.addSwitch('s3', cls=LinuxBridge, failMode='standalone', stp=1)
    s5 = net.addSwitch('s5', cls=LinuxBridge, failMode='standalone', stp=1)

    info( '*** Add hosts\n')
    h5 = net.addHost('h5', cls=Host, ip='12.0.0.1', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, ip='13.0.0.1', defaultRoute=None)
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='11.0.0.1', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(h2, s2)
    net.addLink(h3, s3)
    net.addLink(s1, s4)
    net.addLink(s2, s4)
    net.addLink(s3, s5)
    net.addLink(s2, s5)
    net.addLink(s4, s5)
    net.addLink(s4, r6)
    net.addLink(s5, r7)
    net.addLink(r6, r8)
    net.addLink(r7, r8)
    net.addLink(h5, r6)
    net.addLink(h6, r7)
    net.addLink(h4, r8)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s2').start([])
    net.get('s4').start([])
    net.get('s1').start([])
    net.get('s3').start([])
    net.get('s5').start([])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNetwork()

Add a comment
Know the answer?
Add Answer to:
In this assignment you will start with Python code that builds a 2 host network connected...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE ATTACH A SCREENSHOT OF YOUR SUCCESSFUL PING IN PACKET TRACER FOR THE END!!!!!!!!!!! THANK YOU! Objectives Part...

    PLEASE ATTACH A SCREENSHOT OF YOUR SUCCESSFUL PING IN PACKET TRACER FOR THE END!!!!!!!!!!! THANK YOU! Objectives Part A: Configure a simple static routing . Part B: Configure a simple RIP routing Part A: Configure a simple static routing 1. Create the following network topology on Packet Tracer Router-PT Router-PT Addressing Table Device Interface IP Address Subnet Mask Default Gatewa 10.0.0.1 20.0.0.1 30.0.0.1 20.0.0.2 0.0.0.10 30.0.0.10 N/A 255.0.0.0 255.0.0.0 255.0.0.0 255.0.0.0 255.0.0.0 255.0.0.0 Routero 2/0 NIA NIA NIA 10.0.0.1 30.0.0.1...

  • CHAPTER 4: CONTINUE ll. Multicast Routing Consider the network topology in Figure-2 below H1 NET-...

    CHAPTER 4: CONTINUE ll. Multicast Routing Consider the network topology in Figure-2 below H1 NET- Router R1 R3 R2 R10 R4 R5 R6 R7 R8 R9 NET-4 NET-3 NET-2 H3 H5 H4 Figure 2: Multicast/Broadcast Topology CHAPTER 4: CONTINUE I. Multicast Routing - Continue Q3. Assume the host H1 is willing to multicast a message to the hosts H3, H4, and H5. Assume a center-based tree approach is used for multicast, R5 is selected as the center, and number-of-hops is...

  • Description: In this assignment, you will be launching a denial of service attack on a web...

    Description: In this assignment, you will be launching a denial of service attack on a web server. We will be using hping3, a command-line oriented network security tool inside Kali Linux (an advanced penetration testing Linux distribution). Setting up the victim machine Download the Windows XP virtual machine with WebGoat server installed, using the following link. We will use this machine as the victim machine and launch a DoS attack on the WebGoat server.https://drive.google.com/open?id=0BwCbaZv8DevUejBPWlNHREFVc2s Open the victim machine and launch...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT