inet-framework / inet

INET Framework for the OMNeT++ discrete event simulator
https://inet.omnetpp.org
Other
429 stars 482 forks source link

ExtLowerUdp "Cannot change network namespace" #846

Closed Hikari1026 closed 1 year ago

Hikari1026 commented 1 year ago

Hi everyone, I'm trying to set up a UDP app that communicates over the real network via Emulation feature. I followed the docs for network emulation and managed to successfully run the pinger example, then I tried to implement a SimpleUdpApp with an ExtLowerUdp with virtual interfaces but whenever I run the simulation I get the following error: Cannot change network namespace -- in module (inet::ExtLowerUdp) AppContainer.udp.

This is my current configuration (basically the same code as the one in the docs):

AppContainer.ned

import inet.applications.contract.IApp;
import inet.emulation.transportlayer.udp.ExtLowerUdp;
import inet.networklayer.common.InterfaceTable;

network AppContainer
{
    submodules:
        app: <> like IApp;
        udp: ExtLowerUdp;
    connections allowunconnected:
        app.socketOut --> udp.appIn;
        app.socketIn <-- udp.appOut;
}

omnetpp.ini

[General]
network = AppContainer
scheduler-class = "inet::RealTimeScheduler"

*.app.typename = "UdpBasicApp"
*.app.sendInterval = 1s
*.app.localPort = -1
*.app.destPort = 60001
*.app.messageLength = 100B
*.app.localAddress = "192.168.2.1"
*.app.destAddress = "192.168.2.2"

*.udp.namespace = "net0"

I also did run the commands in order to setup the virtual interfaces

# create namespaces
ip netns add net0
ip netns add net1

# create a virtual ethernet interface in each namespace, assign IP addresses to them and bring them up
ip link add veth0 netns net0 type veth peer name veth1 netns net1
ip netns exec net0 ip addr add 192.168.2.1 dev veth0
ip netns exec net1 ip addr add 192.168.2.2 dev veth1
ip netns exec net0 ip link set veth0 up
ip netns exec net1 ip link set veth1 up

# add routes
ip netns exec net0 route add -net 192.168.2.0 netmask 255.255.255.0 dev veth0
ip netns exec net1 route add -net 192.168.2.0 netmask 255.255.255.0 dev veth1

I know it's probably some silly mistake, but do you have idea about why this isn't working? Thanks!

ZoltanBojthe commented 1 year ago

Changing the network namespace requires cap_sys_admin authority for the setns() function in the inet::NetworkNamespaceContext constructor. This can be set with the command sudo setcap cap_sys_admin+ep /<your-omnetpp-root>/bin/opp_run_dbg, but this is dangerous because it enables a thousand other things for all running simulations, it becomes a big security hole. The sudo also requires for run the network setup script.