Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Wiki / PhantomNet / OEPC-Protected / sample-ns / oepc-delay-ns

oepc-delay-ns

Basic OpenEPC setup with link/lan shaping support.
#
# NS file for instantiating an OpenEPC setup - with link shaping support!
#
# Look for the variable definitions near the top to adjust the composition
# of the resultant OpenEPC system.
#
source tb_compat.tcl

set ns [new Simulator]

##############################################################################
#
# Variables you can tweak w/o necessarily understanding this NS file.
#

# OS to use on the nodes.  This image must be one that has been prepared
# the way OpenEPC expects!
set OEPC_OS "UBUNTU12-64-BINOEPC"

# Were to log the output of the startup command on each node
set OEPC_LOGFILE "/var/tmp/openepc_start.log"

# Set hardware type. "pc" means generic x86-compatible
set OEPC_HWTYPE "pc"

# Location of OpenEPC-in-Emulab startup script
set OEPC_SCRIPT "/usr/bin/sudo /proj/PhantomNet/bin/start_epc.sh"

# Number of clients to allocate (currently, value can be 1 or 2)
set num_clients 1

##############################################################################
#
# Code to generate OpenEPC topology and set it up follows.
#
set nodelist ""
set clientlist "alice bob"

# List of lans that nodes may be added to below.
set lanlist "mgmt net_a net_b net_d an_lte"

# Initialize lan membership lists
array set lans {}
array set lanconf {}
foreach lan $lanlist {
    set lans($lan) ""
    set lanconf($lan) ""
}

proc addtolan {lan node {bw ""} {delay ""}} {
    global lans
    global lanconf
    lappend lans($lan) $node
    if {$bw != {} || $delay != {}} {
        lappend lanconf($lan) [list $node $bw $delay]
    }
}

proc epcnode {node {role ""} {hname ""} {prescr ""} {postscr ""}} {
    global nodelist
    global OEPC_OS OEPC_LOGFILE OEPC_SCRIPT OEPC_HWTYPE

    uplevel "set $node \[\$ns node]"
    lappend nodelist $node
    tb-set-hardware $node $OEPC_HWTYPE
    tb-set-node-os $node $OEPC_OS
    # tb-set-node-failure-action $node "nonfatal"
    addtolan mgmt $node
    if {$role != {}} {
        set startcmd "$OEPC_SCRIPT -r $role"
        if {$hname != {}} {
            append startcmd " -h $hname"
        }
        if {$prescr != {}} {
            append startcmd " -P $prescr"
        }
        if {$postscr != {}} {
            append startcmd " -T $postscr"
        }
        append startcmd " >& $OEPC_LOGFILE"
        tb-set-node-startcmd $node $startcmd
    }
}

if {$num_clients < 1 || $num_clients > 2} {
    perror "num_clients must be 1 or 2!"
    exit 1
}

# Create $num_clients client nodes
for {set i 0} {$i < $num_clients} {incr i} {
    set clnode [lindex $clientlist $i]
    epcnode $clnode "epc-client" $clnode
    addtolan an_lte $clnode
}

# Create the epc-enablers node (Mandatory)
epcnode epc "epc-enablers"
addtolan net_a $epc

# Create the pgw node (Mandatory)
epcnode pgw "pgw"
addtolan net_a $pgw
# example delay, w/ default PHY bandwidth.
addtolan net_b $pgw {} 24ms

# Create the sgw-mme-sgsn node (Mandatory)
epcnode sgw "sgw-mme-sgsn"
# example delay/bw
addtolan net_b $sgw 100Mb 24ms
addtolan net_d $sgw

# Create the enodeb RAN node (Optional)
epcnode enb "enodeb"
addtolan an_lte $enb
addtolan net_d $enb

# Create all lans that have at least two members
foreach lan $lanlist {
   # Since DNS doesn't officially allow underscores, we have to convert
   # them to dashes in the names of the lans before instantiation.
   set nslan [regsub -all -- "_" $lan "-"]
   if {[llength $lans($lan)] > 1} {
       set $nslan [ns make-lan $lans($lan) * 0ms]
   }
   foreach nent $lanconf($lan) {
      set node  [lindex $nent 0]
      set bw    [lindex $nent 1]
      set delay [lindex $nent 2]
      if {$bw != {}} {
          tb-set-node-lan-bandwidth $node $nslan $bw
      }
      if {$delay != {}} {
          tb-set-node-lan-delay $node $nslan $delay
      }
   }
}

# Go!
$ns run