Amazon EC2 Mininet Setup

Amazon has generously offered to provide $100 Amazon Web Services (AWS) account credits to each student in Stanford CS244, Advanced Topics in Networking, for Spring 2012.  This credit will provide plenty of time to run each assignment, and as a side benefit, you’ll get a taste of what computing in the cloud is like.  If you’re familiar with SSHing into a remote machine using public keys, creating and logging into an instance will be no problem.  If not, it’s time to learn, and it’s a useful skill.

The TAs would prefer students to spend their time doing assignments and learning, rather than setting up infrastructure - so if there’s some way to improve these instructions, please let the TAs know.  Thanks!

Request an Account Credit

Setup AWS Account

Prerequisites: credit card, telephone number.

Setup Public Key Authentication

Prerequisite: SSH client.  Pre-installed on Mac and most Linux distros.  On Windows, install Git Bash shell as described in the GitHub Windows tutorial.

Setting up public key authentication is probably the scariest part of the whole process, if you haven’t done it before.  Don’t worry.  It’s really not that bad.

Please check every possibility on this page, ask a friend for help, AND Google your error message before posting on Piazza.  GitHub has a nice page for SSH key debugging.  SSH key debugging can be slow to debug remotely.

If you’re familiar with the process and already have a key, skip to the “Only if you generated... “ bullet point below.

Launch an EC2 Instance

For CS244, the TAs provide a pre-built VM for you to use.  This will have everything you need to run Mininet pre-installed; you’ll only need to pull in code for specific assignments on top.  To create your EC2 instance:

Modify Security Group Settings

Logging in to your Instance

High-level idea: use public-key encryption to connect to your instance via an SSH terminal.

Testing Mininet

As a quick sanity check, make sure that you can run Mininet on your instance:

    sudo mn --link tc,bw=10 --test iperf

This command will start a single-switch topology with 10Mbps links and run iperf between them.  The output should look something like this:

*** Creating network

*** Adding controller

*** Adding hosts:

h1 h2

*** Adding switches:

s1

*** Adding links:

(10.00Mbit) (10.00Mbit) (h1, s1) (10.00Mbit) (10.00Mbit) (h2, s1)

*** Configuring hosts

h1 h2

*** Starting controller

*** Starting 1 switches

s1 (10.00Mbit) (10.00Mbit)

*** Iperf: testing TCP bandwidth between h1 and h2

*** Results: ['9.48 Mbits/sec', '10.2 Mbits/sec']

*** Stopping 2 hosts

h1 h2

*** Stopping 1 switches

s1 ...

*** Stopping 1 controllers

c0

*** Done

completed in 9.457 seconds

Logging out of the Instance

Logging back in to your Instance

Managing your AWS Credit

This section has no action items, but it does have some useful tips.

At  this point, you should be ready to begin Assignment 1.  You can do some optional setup below, or skip to the assignment.

[Optional] Easier Login

Linux or OS X: For easier login you may want to add an entry to ~/.ssh/config with the name of the VM and a few parameters.  Then you can log in to the VM with `ssh vmname’, with no password needed

Add the following to ~/.ssh/config, with the correct hostname from Public DNS:

Host cs244

  User ubuntu

  Hostname ec2-XX-YY-ZZ...compute-1.amazonaws.com

If using a non-default key, you may want to specify the key location below Hostname and replace yourname:

  IdentityFile /Users/yourname/yourkey.pem

[Optional] Changing the Username

Perhaps you like to use your SUNET id when logging into other services, like GitHub, or other remote services using SSH.  The benefit of this approach is that it sets the default username.

Adding your own user name to sudo requires a few steps.  Since authentication is keypair based, it helps to copy the key over to the new username first.

On remote EC2 instance, replacing yourid with the correct username:

sudo adduser yourid

sudo mkdir /home/yourid/.ssh/

sudo cp /home/ubuntu/.ssh/authorized_keys /home/yourid/.ssh/authorized_keys

sudo chown -R yourid.yourid /home/yourid/.ssh

Also modify /etc/sudoers with a line that gives your username root privileges.

sudo bash -c "echo \"yourid ALL=NOPASSWD: ALL\" >> /etc/sudoers"

Then you can login with your normal username.  You may want to change the User line in ~/.ssh/config on your local machine, too.

[Optional] Agent Forwarding

Many students will want to use a source code revision control system.  The TAs are fans of BitBucket, which gives free unlimited private accounts to those with .edu addresses.  Services like BitBucket and GitHub use SSH public key encryption, and it’s good practice to only keep your private key on your local machine.  When logging in, add the -A option to OpenSSH, and it will make your private key available to the remote EC2 instance, without storing it there.  

(Optional) Other Resources

EC2 command-line tools

http://aws.amazon.com/developertools/351

http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/setting-up-your-tools.html

SSH tutorials:

Linux tutorial

Deprecated Content