29
meetup #3 Mininet shanyu@sdnds-tw

SDNDS.TW Mininet

  • Upload
    nctu

  • View
    841

  • Download
    1

Embed Size (px)

Citation preview

Page 1: SDNDS.TW Mininet

meetup #3

Mininet shanyu@sdnds-tw

Page 2: SDNDS.TW Mininet

About me

❖ Shanyu a.k.a. Leader31

❖ 碩二研究生

❖ NCTU Wireless Internet Lab

❖ Logdown: http://shanyu.logdown.com

❖ Github: https://github.com/evelyn3648/MininetTopo

Page 3: SDNDS.TW Mininet

Outline

❖ Introduction to Mininet

❖ Mininet basic operation

❖ Mininet Use Scenario

Page 4: SDNDS.TW Mininet

Mininet version❖ Download: http://mininet.org/download/

❖ Default version: 2.1.0

❖ Newest version: 2.2.0b1

❖ Improved OpenFlow 1.3 support

❖ Mininet 2.1.0 support OpenFlow 1.3

❖ http://www.sdnlab.com/3460

❖ ovs-vsctl set bridge XX protocols=OpenFlow13

❖ Upgrade OVS

❖ http://www.sdnlab.com/3679

Modify mininet/mininet/node.py

Page 5: SDNDS.TW Mininet

What Is Mininet?

❖ 工欲善其事必先利其器

❖ Mininet is a network emulator

❖ “Mininet creates a realistic virtual network, running real kernel, switch and application code, on a single machine (VM, cloud or native)” –mininet.org

❖ Mininet uses lightweight virtualization to make a single system look like a complete network

Page 6: SDNDS.TW Mininet

Testbed

Platform Advantages Disadvantages

Hardware Testbed realityaccurate: "ground truth"

expensiveshared resource?hard to reconfigurehard to change

Simulator inexpensive, flexibledetailed (or abstract!)virtual time (can be "faster" than reality)

may require app changesmight not run OS codemay not be "believable"may be slow/non-interactive

Emulator inexpensive, flexiblereal codereasonably accuratefast/interactive usage

slower than hardwareexperiments may not fitpossible inaccuracy from multiplexing

Page 7: SDNDS.TW Mininet

A simple network topology

S1

h1 h2

firefox httpd

Page 8: SDNDS.TW Mininet

Full System Virtualization

Page 9: SDNDS.TW Mininet

Lightweight Virtualization(Network Namespaces and Virtual Ethernet pairs)

virtual Ethernet pairs

Network namespace: logically another copy of the network stack, with its own routes, firewall rules, and network devicesVirtual Ethernet pairs: A veth pair is a pair of virtual interfaces that act as astraight through connection.

Page 10: SDNDS.TW Mininet

Lightweight Virtualization & Performance modeling with Linux

Network component or

property

Modeling mechanism Configuration command(s)

Hosts Processes in network namespaces

ip netns

Links Virtual Ethernet pairs ip link

Switches Software switches (OVS) ovs-vsctl

Controllers Processes controller

Link performance Traffic Control (Bandwidth,Delay, loss, max queue)

tc

CPU performance CPU Control Groups cg{create,set,delete,classify}

Page 11: SDNDS.TW Mininet

Create it with Linux commandsudo bash# Create host namespacesip netns add h1ip netns add h2# Create switchovs-vsctl add-br s1# Create linksip link add h1-eth0 type veth peer name s1-eth1ip link add h2-eth0 type veth peer name s1-eth2ip link show# Move host ports into namespacesip link set h1-eth0 netns h1ip link set h2-eth0 netns h2ip netns exec h1 ip link showip netns exec h2 ip link show# Connect switch ports to OVSovs-vsctl add-port s1 s1-eth1ovs-vsctl add-port s1 s1-eth2ovs-vsctl show# Set up OpenFlow controllerovs-vsctl set-controller s1 tcp:127.0.0.1ovs-controller ptcp: &ovs-vsctl show

# Configure networkip netns exec h1 ifconfig h1-eth0 10.0.0.1ip netns exec h1 ifconfig lo upip netns exec h2 ifconfig h2-eth0 10.0.0.2ip netns exec h1 ifconfig lo upifconfig s1-eth1 upifconfig s1-eth2 up# Test networkip netns exec h1 ping -c1 10.0.0.2

Controller

S1

h1 h2

將virtual interface/link綁訂到對應host的namespace

建立veth連線和兩端的virual interface

Page 12: SDNDS.TW Mininet

Mininet object

Page 13: SDNDS.TW Mininet

Classes in Mininet Topo

mininet.topo.Topo

mininet.topo.LinearTopo

mininet.topo.SingleSwitchTopo

mininet.topo.SingleSwitchReversedTopo

mininet.topolib.TreeTopo

mininet.topolib.TorusTopo

linear,n: 每個switch (s1-s2-s3…-sn)上各有一個host (h1,h2…,hn)

single,k: 一台switch上面有k個host (h1…,hk) [default topology (h1 - s1 - h2)]

reverse,k:一台switch上面有k個host (hk…,h1)

tree,depth=d,fanout=f: 一顆深度為d,每個node有f個child的tree

2-D Torus topology: this topology has LOOPS

Default

NEW

Page 14: SDNDS.TW Mininet

Classes in Mininet Nodemininet.node.Node

mininet.node.Controller

mininet.node.Host

mininet.node.Switch

mininet.node.Nox

mininet.node.OVSController

mininet.node.RemoteController

mininet.node.CPULimitedHost

mininet.node.IVSSwitch

mininet.node.OVSLegacyKernelSwitch

mininet.node.OVSSwitch

mininet.node.UserSwitch

mininet.node.OVSBridge

mininet.node.RYU

mininet.node.NAT

mininet.nodelib.LinuxBridge

Default

NEW

Page 15: SDNDS.TW Mininet

Classes in Mininet Link

mininet.link.Link mininet.link.Intf

mininet.link.TCLink

mininet.link.TCIntf

Basic interface object that can configure itselfA basic link is just a veth pair

Page 16: SDNDS.TW Mininet

Mininet basic operation

Page 17: SDNDS.TW Mininet

Mininet command line

❖ $sudo mn

連線到外部controller $sudo mn –controller=remote,ip=<ip>,port=<port>Default ip: 127.0.0.1Default port: 6633 (IANA define OpenFlow port:6653)

Page 18: SDNDS.TW Mininet

Mininet basic Command❖ 顯示 nodes (controllers, hosts, switches) 列表

❖ mininet> nodes

❖ 顯示 links 列表

❖ mininet> net

❖ 顯示 nodes 詳細資訊

❖ mininet> dump

❖ 離開 CLI

❖ mininet> exit

❖ mininet> <ctrl>+D

❖ 清除 Mininet

❖ sudo mn –c

Page 19: SDNDS.TW Mininet

Virtual Switch / Datapath 管理

❖ 所有 virtual switches 狀態

❖ mininet> dpctl show

❖ 所有 switches 支援的 OpenFlow versions

❖ mininet> dpctl –version

❖ 註: OF1.0 = 0x01, OF1.3 = 0x04

❖ 所有 switches 上所有 flow entries

❖ mininet> dpctl dump-flows

❖ 所有 switches 上 ports 的流量統計

❖ mininet> dpctl dump-ports

Page 20: SDNDS.TW Mininet

Custom network topology

❖ Mininet script with python API

❖ Low-level API: Node and Links

❖ Mid-level API: Network Object

❖ High-level API: Topology templates

❖ sudo mn –custom ./<XXX.py> --topo XXX

❖ api.mininet.org

❖ docs.mininet.org

❖ Introduction to Mininet

❖ Some examples in mininet/example

Controller

S1

h1 h2

Page 21: SDNDS.TW Mininet

Low-level API: Node and Links

h1 = Host( 'h1' ) h2 = Host( 'h2' ) s1 = OVSSwitch( 's1', inNamespace=False ) c0 = Controller( 'c0', inNamespace=False ) Link( h1, s1 ) Link( h2, s1 ) h1.setIP( '10.1/8' ) h2.setIP( '10.2/8' ) c0.start() s1.start( [ c0 ] ) s1.stop() c0.stop()

Controller

S1

h1 h2

Page 22: SDNDS.TW Mininet

Mid-level API: Network object

net = Mininet() h1 = net.addHost( 'h1' ) h2 = net.addHost( 'h2' ) s1 = net.addSwitch( 's1' )c0 = net.addController( 'c0' ) net.addLink( h1, s1 ) net.addLink( h2, s1 ) net.start()CLI( net ) net.stop()

Controller

S1

h1 h2

Page 23: SDNDS.TW Mininet

High-level API: Topology templates

class SingleSwitchTopo( Topo ):"Single switch connected to k hosts.“

def build( self, k=2, **opts ):"k: number of hosts"self.k = kswitch = self.addSwitch( 's1' )for h in irange( 1, k ):

host = self.addHost( 'h%s' % h )self.addLink( host, switch )

net = Mininet( topo=SingleSwitchTopo( 2 ) ) net.start() CLI( net ) net.stop()

Controller

S1

h1 h2

Page 24: SDNDS.TW Mininet

Mininet Use Scenario

Page 25: SDNDS.TW Mininet

Mininet hosts connect to internet

❖ Method1: create node (NAT)

❖ through host OS

❖ Iptables command

❖ MASQUERADE, ip_forward

❖ Method2: via OVS command

❖ ovs-vsctl add-port s1 eth0

❖ Host OS also want to access internet

❖ http://rascov.logdown.com/posts/231057-bridge-mininet-to-the-internet

Page 26: SDNDS.TW Mininet

Mininet multi hosts want to run same service

❖ Mininet hosts share the same file system

❖ Problem: multi hosts can’t run same daemon (snmpd, httpd) at the same time

❖ service XXX start/restart/stop

❖ Web Server

❖ python -m SimpleHTTPServer 80 &

❖ Snmp

❖ /usr/sbin/snmpd -LS n d -Lf /dev/null -p /var/run/snmpd.pid

❖ Problem: get same CPU usage form all hosts

Page 27: SDNDS.TW Mininet

Multisubnet❖ S1 be a Router (gateway)

❖ Create a gateway host

❖ Modify routing table & ip_forward on gateway host❖ http://shanyu.logdown.com/posts/223708-mininet-with-multi-subnet

❖ Mininet add linuxrouter node in upcoming version❖ https://github.com/mininet/mininet/blob/65e33fed9b1d583a90c9dd09e6fd64e5

354b377c/examples/linuxrouter.py

❖ Controller act ARP proxy (OpenDaylight)

❖ Using flow rule let switch be a gateway router

❖ http://hwchiu.logdown.com/posts/203260-mininet-and-network-subnet

10.0.0.0/24

10.1.0.0/24

10.2.0.0/24S1

Page 28: SDNDS.TW Mininet

References❖ Tutorial at SIGCOMM 2014

❖ https://github.com/mininet/mininet/wiki/Teaching-and-Learning-with-Mininet

❖ SDNLAB

❖ http://www.sdnlab.com/

❖ Hwchiu blog

❖ http://hwchiu.logdown.com/

❖ Rascov blog

❖ http://rascov.logdown.com/

Page 29: SDNDS.TW Mininet

Thank you