##############################################
# This script defines the experiment
# that has one sender and one receiver
# Sender, Receiver - 802.11a channel 36
# UDP flow at varying offer load
############################################################

require 'net/http'
require 'uri'

Experiment.name = "rateudp"
Experiment.project = "orbit:tutorial"

rates = [8000, 9000, 10000, 11000, 12000]

Experiment.defProperty('offerload', 500, 'offered load of flow')
Experiment.defProperty('packetsize',1024, 'size of flow')

#
# Define nodes used in experiment
#
###########################################
# Sender definition and configuration
###########################################
defNodes('sender', [1,2]) {|node|
  node.image = nil  # assume the right image to be on disk
  # use prototype "sender"
  # and set it's property "destinationHost" to
  # the receiver node
  # and bind the remaining properties to the
  # experiment property space
  node.prototype("test:proto:sender", {
     'destinationHost' => '192.168.1.1',
     'packetSize' => prop.packetsize,
     'rate' => prop.offerload,
  'protocol'=> 'udp'
    })
  node.net.w0.ip = "%192.168.%x.%y"
  node.net.w0.mode = "Master"
  node.net.w0.type = 'b'
  node.net.w0.essid = "helloworld"
  node.net.w0.channel = 1
  node.net.w0.rate= '11M'
}
###########################################
# Receiver definition and configuration
###########################################

defNodes('receiver', [1,1]) {|node|
  node.net.w0.ip = "%192.168.%x.%y"
  node.image = nil  # assume the right image to be on disk
  node.prototype("test:proto:receiver" , {
   'protocol' => 'udp_libmac',
   'hostname' => '192.168.1.1'
  })
  node.net.w0.mode = "Managed"
  node.net.w0.type = 'b'
  node.net.w0.essid = "helloworld"
}

###########################################
# When nodeAgents have reported "OK" to
# the nodeHandler start the application
###########################################
whenAllInstalled() {|node|

  nodes('receiver').startApplications
  nodes('sender').startApplications

 rates.each {|rate_level|
wait 20
  prop.packetsize= 52
  prop.offerload =50
  wait 30
  prop.packetsize= 1024
  prop.offerload= rate_level
 }

  allNodes.stopApplications

  Experiment.done

}