Search code examples
mininet

How to use setCPUFrac in mininet?


I'm using Mininet to emulate a simple network with sudo mn, which creates a two hosts network. Now I want to allocate a specific CPU rate for each host. I know this is possible by using setCPUFrac, but I couldn't manage to use it successfully.

How to use the function from the command line? I tried things like :

h1 setCPUFrac( f=-1,sched=None)
h1 setCPUFrac(f="1")
h1 setCPUFrac(f=1)
setCPUFrac(h1, f=-1,sched=None)

and all gave me :

bash: syntax error near unexpected token

Note: I'm new to Mininet.


Solution

  • the command that you run, executes setCPUFrac( f=-1,sched=None) on h1, that's why you have a bash error.

    You need to be sure that the host Type is CPULimitedHost otherwise, it doesn't have the method setCPUFrac

    From the mn command line you can run the network using the limited hosts with --host cfs,sched=None and then use the py command to do the trick in the mn command line.

    i.e.

    root@raspberrypi:~# mn  --host cfs,sched=None
    *** Creating network
    *** Adding controller
    *** Adding hosts:
    h1 h2
    *** Adding switches:
    s1
    *** Adding links:
    (h1, s1) (h2, s1)
    *** Configuring hosts
    h1 h2
    *** Starting controller
    c0
    *** Starting 1 switches
    s1 ...
    *** Starting CLI:
    mininet> py net.getNodeByName("h1").setCPUFrac( f=-1,sched=None)
    mininet>
    

    Or you can build a python script following the mininet API