Showing posts with label EC2. Show all posts
Showing posts with label EC2. Show all posts

Tuesday, 7 August 2012

Install and run NS3 on Amazons EC2

This is simple step-by step on how to run NS3 on Amazon cloud. If you skip to 3 you can use same script on any other machine using Ubuntu.

This script will install needed packages, download ns3, make standard configuration, build ns-3-dev, and will run test.

Assuming you have Amazon account.

  1. Create Ubuntu 12.04 image
  2. Log in to it
  3. Create file installns3.sh
  4. vi installns3.sh
    i
    
  5. Copy following code into it:
  6. #!/bin/bash
    #original timer was published in
    #http://www.linuxjournal.com/
    #http://tiny.cc/en2niw 
    #by Mitch Frazier
    function timer()
    {
     if [[ $# -eq 0 ]]; then
      echo $(date '+%s')
     else
      local  stime=$1
      etime=$(date '+%s')
             if [[ -z "$stime" ]]; then stime=$etime; fi
             dt=$((etime - stime))
             ds=$((dt % 60))
             dm=$(((dt / 60) % 60))
      dh=$((dt / 3600))
      printf '%d:%02d:%02d' $dh $dm $ds
     fi
    }
    tmr=$(timer)
    INSTALL_DIR="/home/ubuntu/dev/ns3"
    #files to install 
    APPS="gcc g++ python python-dev mercurial bzr gdb valgrind gsl-bin \
     libgsl0-dev libgsl0ldbl flex bison libfl-dev tcpdump sqlite sqlite3 \
     libsqlite3-dev libxml2 libxml2-dev libgtk2.0-0 libgtk2.0-dev vtun \
     lxc uncrustify doxygen graphviz imagemagick texlive texlive-extra-utils \ 
     texlive-latex-extra python-sphinx dia python-pygraphviz python-kiwi \
     python-pygoocanvas libgoocanvas-dev libboost-signals-dev \ 
     libboost-filesystem-dev openmpi-bin libopenmpi-dev openmpi-doc"
    # update repos
    RETVAL=$(sudo apt-get update)
    if [ $? -ne 0 ]; then
     echo "Unable to update, reason: $?"
     echo $RETVAL
     exit 1
    else
     echo "Successfully updated app repostitory"
    fi
    #function to handle instaliation 
    function make_install(){
     if [ $# == 0 ]; then
             echo "must give at least one argument"
      exit 1
     fi
     for app in $*
     do
      #we do not care is packet is installed it is success
      RETVAL=$(sudo apt-get install -y $app 2>&1 >/dev/null)
      if [ $? -ne 0 ]; then
       echo "Failure: can't install $app reson: $?"
              echo $RETVAL
              echo "Skipping package $app" 
      else
       echo "Succesfully installed $app"
      fi
    
     done
    }
    
    #create directory
    if [ ! -d "$INSTALL_DIR" ]; then
     echo "Creating $INSTALL_DIR"
     RET=$(mkdir -p $INSTALL_DIR 2>&1 >/dev/null)
     if [ $? -ne 0 ]; then
      echo "Can not create directory $INSTALL_DIR. Reason: $?"
      echo $RET
      exit 1
     else
      echo "Succesfully created directory $INSTALL_DIR"
     fi
    fi
    #check if port is open
    
    #install apps
    make_install $APPS
    
    cd $INSTALL_DIR
    echo "Cloning repo"
    RET=$(hg clone http://code.nsnam.org/ns-3-allinone)
    if [ $? -ne 0 ]; then
     echo "Could not clone ns-3-allinone. REASON: $?"
     echo $RET
     exit 1
    else
     echo "Cloning was successfull"
    fi
    cd "ns-3-allinone"
    echo "Downloading ns3-dev"
    chmod +x download.py
    ./download.py -n ns-3-dev
    cd "ns-3-dev"
    echo "Building standart ns3"
    ./waf configure --enable-tests
    ./waf build
    echo "Running test"
    chmod +x test.py
    ./test.py
    printf 'Elapsed time: %s\n' $(timer $tmr) 
    echo "Thank you! Enjoy NS3"
    
  7. Save file and execute it.
  8. #hit esc
    :wq
    chmod +x installns3.sh
    ./installns3.sh
    #go grab coffee
    
  9. It will take a while, I was using medium instance which took: ~34 min.
If you are to lazy to copy paste and bother, find "ubuntu-12.04-ns-3-dev" AMI in community AMI's I have published pre-installed and pre-build version of the image. It will save you time and buck too!

Cheers :)

Monday, 6 August 2012

Wireshark on AWS EC2

Updated on 28th Mars 2014, thanks Imran Hayder for suggestions! In some cases you may need to run wireshark on remote machine, especially if you want to in depth to understand what is going on.
Without any further blah blah, amusing you are using Ubuntu here is how to:

  1. Create EBS, make sure to un-check "delete on termination"
  2. Create and start Ubuntu 12.04 EC2
  3. Log in to it
  4. Check disk name
  5. sudo fdisk -l 
    
  6. Format disk
  7. sudo mkfs -t ext4 /device/path
    
  8. Create mount directory
  9. sudo mkdir /home/data-storage
    
  10. Mount disk
  11. sudo mount /dev/DEVICE /home/data-storage
    
  12. Make wireshark folder
  13. sudo mkdir /home/data-storage/wireshark
    #important change ownership!
    sudo chown root:ubuntu /home/data-storage/wireshark
    #allow group to read
    sudo chmod -R 774 wireshark
    
  14. Install wireshark
  15. sudo apt-get install wireshark tshark
    
  16. Run example
  17. sudo su
    cd /home/data-storage/wireshark
    #tshark will capture eth0 for 10 seconds and save file to my.pcap
    tshark -i eth0 -a duration:10 -w my.pcap
    
  18. Copy file to local
  19. #from your local machine, note intentional line brake due to layout of the blog.
    cd wireshark
    scp -i your.pem 
       ubuntu@your_ec2_dns.compute.amazonaws.com:/path-to/my.pcap .
    
Read the comments bellow for trouble shooting. Note, it is not advisable to copy paste commands since you may bet the html representation, and not what you should type in the terminal.