Mininet + K3S

Based on nginx-rtmp docker and k3s, I write this lab.

 

[Topology]

 

[dockerhost3.py]

#!/usr/bin/python

 

"""

This example shows how to create a simple network and

how to create docker containers (based on existing images)

to it.

"""

 

from mininet.net import Containernet

from mininet.node import Controller, Docker, OVSSwitch

from mininet.cli import CLI

from mininet.log import setLogLevel, info

from mininet.link import TCLink, Link

 

 

def topology():

 

    "Create a network with some docker containers acting as hosts."

 

    net = Containernet(controller=Controller)

 

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

    h1 = net.addHost('h1', ip="192.168.1.1/24")

    h2 = net.addHost('h2', ip="192.168.2.1/24")

    h3 = net.addHost('h3', ip="192.168.3.1/24")

 

    info('*** Adding docker containers\n')

    d1 = net.addDocker('d1', dimage="busybox:v1")

 

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

    net.addLink(h1, d1)

    net.addLink(h2, d1)

    net.addLink(h3, d1)

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

    net.start()

    d1=net.get('d1')

    h1,h2,h3=net.get('h1','h2','h3')

    d1.cmd("ifconfig d1-eth0 0")

    d1.cmd("ifconfig d1-eth1 0")

    d1.cmd("ifconfig d1-eth2 0")

    d1.cmd("ip addr add 192.168.1.254/24 brd + dev d1-eth0")

    d1.cmd("ip addr add 192.168.2.254/24 brd + dev d1-eth1")

    d1.cmd("ip addr add 192.168.3.254/24 brd + dev d1-eth2")

    d1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")

    h1.cmd("ip route add default via 192.168.1.254")

    h2.cmd("ip route add default via 192.168.2.254")

    h3.cmd("ip route add default via 192.168.3.254")

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

    CLI(net)

 

    info('*** Stopping network')

    net.stop()

 

if __name__ == '__main__':

    setLogLevel('info')

    topology()

 

[Execution]

For k3s part

 

Routing should be set manually.

 

 

For mininet part (you need dockernet to run this example)

 

Open terminal for h1, h2, h3

 

Prepare a test.mp4 for h1 and streaming video (test.mp4) to nginx-rtmp server (172.17.0.1:31805)

 

For h2, h3, use ffplay to play video

 

Results:

(one terminal is for h2 and the other one is for h3)

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.