--- tags: ns-3 --- # ns-3 Setup [TOC] ## VM Setup The process closely follows that of a [previous note](https://hackmd.io/@mcnlab538/sql_amq_prom). Create a Fedora Server 34 VM on *hp* with 16 vcpus, 16GB ram, and 160GB disk: ```bash virt-install \ --name ns3 \ --memory 16384\ --vcpus 16 \ --os-variant fedora34 \ --disk size=160,cache=none,io=native,bus=virtio \ --disk vol=iso/fedora34.iso,device=cdrom \ --boot hd,cdrom,useserial=on \ --network network=default,model=virtio \ --graphics none \ --autostart \ --noreboot \ --noautoconsole virsh start ns3 --console ``` 1. Press `TAB` on boot menu, and append the parameter `console=ttyS0`. 2. Don't set password for root; instead, create an adminstrator account. - Full name: ns3 - User name: *automatically inherits from full name* - Set password - Mark as administrator 4. Configure network. - static ip - ipv4 address: 192.168.122.3/24 - gateway: 192.168.122.1 - dns: 8.8.8.8,8.8.4.4 5. Use `LVM`. 6. NTP: `tw.pool.ntp.org`. 7. Choose closest mirror. 8. Choose *Server Edition* installation. Resize *root* partition. ```bash lvresize /dev/mapper/fedora_ns3-root /dev/vda2 xfs_growfs /dev/mapper/fedora_ns3-root ``` Disable cockpit. ```bash firewall-cmd --zone=FedoraServer --remove-service=cockpit firewall-cmd --runtime-to-permanent systemctl disable cockpit systemctl disable cockpit.socket systemctl stop cockpit systemctl stop cockpit.socket dnf remove cockpit ``` Shutdown the VM (ns3). On *hp*, create the file `/etc/libvirt/hooks/qemu` with content: (the IPs are generic private addresses; eplace them with the specific addresses) ```bash #!/bin/bash # # ZYV # # This horrible script adds and removes iptables rules to allow for port # forwarding from the host machine (virtualization server) to the selected # virtualized guests. # # Unfortunately, libvirt inserts its own FORWARD rules along with final REJECTs # at the very top of the table, so the rules defined via iptables config will # be rendered ineffective, hence the need for this hook. # set -e set -u iptables='/sbin/iptables' # Ideally, rewrite as ERB template and fetch this from Puppet external_ifs='107-hp' external_ip='192.168.99.107' # List the machines here machines=( 'ns3' ) # Machine definition block #jenkins_hostname='jenkins.qa.nest-initiative.org' ns3_ip='192.168.122.3' ns3_sport=( '3000' ) ns3_dport=( '22' ) rules_update() { domain="$1" action="$2" for host in ${machines[@]}; do #eval host_name="\$${host}_hostname" if [ "$domain" == "${host}" ]; then eval host_ip="\$${host}_ip" eval host_sport=( \${${host}_sport[@]} ) eval host_dport=( \${${host}_dport[@]} ) length=$(( ${#host_sport[@]} - 1 )) for i in `seq 0 $length`; do for external_if in ${external_ifs}; do PREROUTING="$iptables -t nat $action PREROUTING -d ${external_ip} -i ${external_if} -p tcp -m tcp --dport ${host_sport[$i]} -j DNAT --to-destination ${host_ip}:${host_dport[$i]}" if [ -z "${DEBUG_RULES:-}" ]; then `$PREROUTING` else echo $PREROUTING fi done FORWARD="$iptables $action FORWARD -d ${host_ip} -p tcp -m state --state NEW -m tcp --dport ${host_dport[$i]} -j ACCEPT" if [ -z "${DEBUG_RULES:-}" ]; then `$FORWARD` else echo $FORWARD fi done fi done } domain_name="$1" domain_task="$2" case "${domain_task}" in # hook is called with <domain_name> start begin - start) rules_update ${domain_name} " -I " ;; # hook is called with <domain_name> stopped end - stopped) rules_update ${domain_name} " -D " ;; # libvirtd restart hook, added in libvirt-0.9.13 reconnect) rules_update ${domain_name} " -D " rules_update ${domain_name} " -I " ;; *) echo "qemu hook called with unexpected options $*" >&2 ;; esac ``` Restart *libvirtd* and the VM, *ns3*: ```bash systemctl restart libvirtd virsh start ns3 ``` Now *ns3* can be accessed from `<external host IP>:<external port>`; in our case it's `192.168.99.107:3000`. ## Installation of NS-3 For the full instruction, refer to the *Fedora/RedHat* section [here](https://www.nsnam.org/wiki/Installation). Install the dependencies: ```bash dnf install --skip-broken \ gcc-c++ \ python3 python3-devel \ git mercurial \ gsl gsl-devel \ qt5-devel \ gtk3 gtk3-devel \ gdb valgrind \ doxygen graphviz ImageMagick \ python3-sphinx dia texlive texlive-latex texlive-fncychap texlive-capt-of texlive-tabulary texlive-eqparbox \ texlive-epstopdf texlive-titlesec texlive-framed texlive-dvipng texlive-threeparttable texlive-wrapfig \ texlive-multirow ImageMagick \ tcpdump \ sqlite sqlite-devel \ libxml2 libxml2-devel \ uncrustify \ mpich mpich-devel environment-modules \ libxml2 libxml2-devel boost-devel \ pygobject3-devel python3-gobject gobject-introspection-devel goocanvas2-devel graphviz-devel graphviz ipython easy_install pygraphviz \ cmake clang-devel llvm-devel llvm-static \ make patch autoconf cvs # Unable to find a match: qt5-devel easy_install pygraphviz pip3 install --user cxxfilt # restart shell module load mpi/mpich-x86_64 ``` Check dependencies with *bake*: ```bash bake.py check ``` However, don't install the source with *bake*, manually install from the official tarball (ver 3.34) intead. ```bash curl -LO https://www.nsnam.org/releases/ns-allinone-3.34.tar.bz2 tar xjvf ns-allinone-3.34.tar.bz2 cd ns-allinone-3.34 tmux ./build.py ./test.py ```