示例#1
0
def emptyNet():

    "Create an empty network and add nodes to it."

    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')

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

    info('*** Creating links\n')
    CSMALink(h1, s3, DataRate="10Mbps")  # line modified
    CSMALink(h2, s3, DataRate="100Mbps")  # line modified

    info('*** Starting network\n')
    net.start()
    mininet.ns3.start()  # line added

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    mininet.ns3.clear()  # line added
    net.stop()
示例#2
0
readline.parse_and_bind("tab: complete")

if __name__ == '__main__':
    setLogLevel('info')
    info('*** ns-3 network demo\n')
    net = Mininet()

    info('*** Creating Network\n')
    h0 = Node('h0')
    h1 = Node('h1')

    net.hosts.append(h0)
    net.hosts.append(h1)

    link = CSMALink(h0, h1, DataRate="10Mbps")

    ns.csma.CsmaHelper().EnablePcap("h0-trace.pcap", h0.nsNode.GetDevice(0),
                                    True, True)
    ns.csma.CsmaHelper().EnablePcap("h1-trace.pcap", h1.nsNode.GetDevice(0),
                                    True, True)

    mininet.ns3.start()

    info('*** Configuring hosts\n')
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')

    info('Testing network connectivity\n')
    net.pingAll()
    info('Testing bandwidth between h0 and h1\n')
示例#3
0
import mininet.ns3
from mininet.ns3 import CSMALink

if __name__ == '__main__':
    setLogLevel('info')
    info('*** ns-3 network demo\n')
    net = Mininet()

    info('*** Creating Network\n')
    h0 = Node('h0')
    h1 = Node('h1')

    net.hosts.append(h0)
    net.hosts.append(h1)

    link = CSMALink(h0, h1)

    mininet.ns3.start()

    info('*** Configuring hosts\n')
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')

    info('*** Network state:\n')
    for node in h0, h1:
        info(str(node) + '\n')

    info('*** Running test\n')
    h0.cmdPrint('ping -c1 ' + h1.IP())

    CLI(net)