• (OK)(OK)(All in CLI) Fedora23 + Docker(busybox) + NS3 + MANETs



    #------------------------------------------------------------------------------------------
    # (OK)(OK)(All in CLI) Fedora23 + Docker(busybox) + NS3 + MANETs - testing
    #------------------------------------------------------------------------------------------

    systemctl start docker.service

    # docker search image_name
    # docker pull image_name
    # docker images
    # docker rmi image_name
    # docker run --privileged -i -t -d --net=none --name docker-$id $docker_image -t $type -i $id
    # docker ps
    docker run -it --rm --net='none' --name docker-1 busybox /bin/sh
    docker run -it --rm --net='none' --name docker-2 busybox /bin/sh

    # get PID of CONTAINER
    [root@localhost ~]# docker inspect -f "{{.State.Pid}}" docker-1
    31321
    [root@localhost ~]# docker inspect -f "{{.State.Pid}}" docker-2
    31357

    # [root@localhost ~]# man ip-netns
    #       By convention a named network namespace is an object at /var/run/netns/NAME that can be opened. The file
    #       descriptor resulting from opening /var/run/netns/NAME refers to the specified network namespace. Holding that
    #       file descriptor open keeps the network namespace alive. The file descriptor can be used with the setns(2) sys‐
    #       tem call to change the network namespace associated with a task.

    #------------------------------------------------------------------------------------------
    # https://www.nsnam.org/wiki/HOWTO_Use_Linux_Containers_to_set_up_virtual_networks
    # http://yaxin-cn.github.io/Docker/docker-container-use-static-IP.html

    #[root@localhost ~]#

    brctl addbr br_d_1
    brctl addbr br_d_2

    ip link add veth_1 type veth peer name X
    brctl addif br_d_1 veth_1
    ip link set veth_1 up
    ip link set X netns 31321

    ip link add veth_2 type veth peer name Y
    brctl addif br_d_2 veth_2
    ip link set veth_2 up
    ip link set Y netns 31357

    tunctl -t tap_d_1
    tunctl -t tap_d_2
    ifconfig tap_d_1 0.0.0.0 promisc up
    ifconfig tap_d_2 0.0.0.0 promisc up

    brctl addif br_d_1 tap_d_1
    ifconfig br_d_1 up
    brctl addif br_d_2 tap_d_2
    ifconfig br_d_2 up

    mkdir /var/run/netns
    ln -s /proc/31321/ns/net /var/run/netns/31321
    ln -s /proc/31357/ns/net /var/run/netns/31357

    ip netns exec 31321 ip link set dev X name eth0
    ip netns exec 31321 ip link set eth0 up
    ip netns exec 31321 ip addr add 172.17.0.1/16 dev eth0

    ip netns exec 31357 ip link set dev Y name eth0
    ip netns exec 31357 ip link set eth0 up
    ip netns exec 31357 ip addr add 172.17.0.2/16 dev eth0

    cd /proc/sys/net/bridge
    for f in bridge-nf-*; do echo 0 > $f; done
    cd -

    # ip netns exec 31321 ip route add default via 172.17.42.1
    # ip netns exec 31357 ip route add default via 172.17.42.1
    # [root@localhost ~]# brctl show
    # / # route -n
    # You will also have to make sure that your kernel has ethernet filtering (ebtables, bridge-nf, arptables) disabled. If you do not do this, only STP and ARP traffic will be allowed to flow across your bridge and your whole scenario will not work.


    #-----------------------
    # running NS3
    #-----------------------
    [root@localhost ~]# cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25

    [root@localhost ns-3.25]# gedit scratch/manet-docker.cc
    #----------------
      TapBridgeHelper tapBridge;
      tapBridge.SetAttribute ("Mode", StringValue ("UseLocal"));
      tapBridge.SetAttribute ("DeviceName", StringValue ("tap_d_1"));
      tapBridge.Install (nodes.Get (0), devices.Get (0));

      tapBridge.SetAttribute ("DeviceName", StringValue ("tap_d_2"));
      tapBridge.Install (nodes.Get (1), devices.Get (1));
    #----------------

    [root@localhost ns-3.25]# ./waf --run scratch/manet-docker --vis

    ------------------------------------------------------
    172.17.0.2 can ping 172.17.0.1 successfully
    ------------------------------------------------------



    ifconfig br_d_1 down
    ifconfig br_d_2 down
    brctl delif br_d_1 tap_d_1
    brctl delif br_d_2 tap_d_2
    brctl delbr br_d_1
    brctl delbr br_d_2

    ifconfig tap_d_1 down
    ifconfig tap_d_2 down
    tunctl -d tap_d_1
    tunctl -d tap_d_2


    ------------------------------------------------------------------------------------------
    So far, OK OK OK
    ------------------------------------------------------------------------------------------

  • 相关阅读:
    第二次作业
    第四次作业
    第三次作业
    第二次作业
    第一次作业
    第四次作业
    第三次作业
    第二次作业
    第一次大学作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/ztguang/p/12646339.html
Copyright © 2020-2023  润新知