topology.ns 5.14 KB
Newer Older
Binh Nguyen's avatar
Binh Nguyen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
#
# NS file for instantiating an OpenEPC setup.
#
# 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-OEPCR5"

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

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

# Set the type of node hardware to use. "pc" is a generic, real PC.
set OEPC_HWTYPE "d710"

# Set the link bandwidth.  Note that "*" (meaning, use the fastest available
# native link speed) is incompatible with link encapsulation.  Since link
# encapsulation is required for virtual nodes, this value has to be changed
# to something specific (e.g., 10Mb) if HWTYPE is set to "pcvm".
set OEPC_LINKBW "*"


# Allocate the enodeb node (and an_lte network)?
# If we allocate, then currently the number can be from 1 to 3.
set alloc_enodeb 1
set num_enodeb 1

# Allocate the epdg node (and an_wifi network)?
set alloc_epdg 0

# Allocate the angw node (and an_wimax network)?
set alloc_angw 0

# Allocate the nodeb node (and an_umts network)?
set alloc_nodeb 0

##############################################################################
#
# Code to generate OpenEPC topology and set it up follows.
#

# Various node lists (referenced by, or filled in by code below)
set nodelist ""
set enblist "enb1 enb2 enb3"

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

# 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
    }
}



# 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
addtolan net_b $pgw

# Create the sgw-mme-sgsn node (Mandatory)
epcnode sgw "sgw-mme-sgsn"
addtolan net_b $sgw
addtolan net_d $sgw

# Add ip.access enodeb node #1
set penb1 [$ns node]
tb-fix-node $penb1 enodeb01
addtolan net_d $penb1


# Create the enodeb RAN node(s) (Optional)
if {$alloc_enodeb} {
    # Check that num_enodeb isn't out of bounds.
    if {$num_enodeb < 1 || $num_enodeb > [llength $enblist]} {
  perror "num_enodeb must be between 1 and [llength $enblist] (inclusive)!"
  exit 1
    }

    # Create the number of enodeb nodes requested.
    for {set i 0} {$i < $num_enodeb} {incr i} {
  set enbnode [lindex $enblist $i]
  epcnode $enbnode "enodeb" $enbnode
  addtolan an_lte $enbnode
  addtolan net_d $enbnode
    }

}

# Create the epdg RAN node (Optional)
if {$alloc_epdg} {
    epcnode epdg "epdg"
    addtolan an_wifi $epdg
    addtolan net_b $epdg
}

# Create the angw RAN node (Optional)
if {$alloc_angw} {
    epcnode angw "angw"
    addtolan an_wimax $angw
    addtolan net_b $angw
}

# Create the nodeb RAN node (Optional)
if {$alloc_nodeb} {
    epcnode nodeb "nodeb"
    addtolan an_umts $nodeb
    addtolan net_d $nodeb
}

# 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) $OEPC_LINKBW 0ms]
  # The default type of link encapsulation for virtual nodes
  # (veth-ne) is antiquated and incompatible with modern XEN.
  if {[string match -nocase "*vm*" $OEPC_HWTYPE]} {
      tb-set-link-encap $nslan "vlan"
  }
  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
      }
  }
    }
}

# Cut down on the number of nodes required in the topology by using
# end-node traffic shaping.
tb-use-endnodeshaping 1

# Go!
$ns run