206 | | '''Hints''' [[BR]] |
| 206 | '''Questions'''[[BR]] |
| 207 | To help user to fetch the information about the amount of traffic as well as the queue depth (measured in number of packets) on both left and right node, we provide a script that the user can download and run on both left and right node [[BR]] |
| 208 | You can download the script from [http://www.gpolab.bbn.com/experiment-support/OpenFlowExampleExperiment/netinfo.py netinfo.py]. Then do the following to start monitoring network usage: [[BR]] |
| 209 | - 1. install Twisted Web package for Python on both left and right node: |
| 210 | {{{ |
| 211 | sudo yum install python-twisted-web |
| 212 | }}} |
| 213 | - 2. upload netinfo.py onto left and right node, then change the listening IP address in netinfo.py to the public IP address of left and right node respectively. i.e., replacing the following 0.0.0.0 in your netinfo.py file to the public IP address of the left/right node. |
| 214 | {{{ |
| 215 | reactor.listenTCP(8000, factory, interface = '0.0.0.0') |
| 216 | }}} |
| 217 | - 3. apply qdisc on interface eth1 of both left and right node by executing (you may further change the parameters by using ''tc qdisc change''): |
| 218 | {{{ |
| 219 | sudo /sbin/tc qdisc add dev eth1 root handle 1:0 netem delay 20ms |
| 220 | sudo /sbin/tc qdisc add dev eth1 parent 1:0 tbf rate 20mbit buffer 20000 limit 16000 |
| 221 | }}} |
| 222 | - 4. run the script by: |
| 223 | {{{ |
| 224 | python netinfo.py |
| 225 | }}} |
| 226 | - 5. verify it is working by opening a web browser and typing the following URL (replacing 155.98.36.69 with your left or right node's public IP address): |
| 227 | {{{ |
| 228 | http://155.98.36.69:8000/qinfo/0 |
| 229 | }}} |
| 230 | For more information about netinfo.py, please look at the comments in the file. [[BR]] |
| 231 | |
| 232 | To help you get started, the following is the ruby class that helps collecting the monitoring results: |
| 233 | {{{ |
| 234 | class DataCollector |
| 235 | @@Weight = 0.2 |
| 236 | |
| 237 | attr_reader :port |
| 238 | |
| 239 | def initialize(host, port) |
| 240 | @host = host |
| 241 | @uri = 'http://' + host + ':8000/qinfo/' |
| 242 | @last = 0 |
| 243 | @ewmabytes = 0 |
| 244 | @ewmapkts = 0 |
| 245 | @lock = Mutex.new |
| 246 | @port = port |
| 247 | end |
| 248 | |
| 249 | def run |
| 250 | starttime = Time.now.to_f |
| 251 | while true |
| 252 | data = Net::HTTP.get(URI(@uri + @last.to_s)) |
| 253 | data.each do |line| |
| 254 | ts, bytes, qlen = line.chomp.split(' ').map { |x| x.to_i } |
| 255 | @lock.synchronize do |
| 256 | if ts <= @last |
| 257 | next |
| 258 | elsif @last == 0 |
| 259 | @ewmabytes = bytes |
| 260 | @ewmapkts = qlen |
| 261 | else |
| 262 | # Just assume we haven't missed too many entries |
| 263 | @ewmabytes = bytes * @@Weight + @ewmabytes * (1 - @@Weight) |
| 264 | @ewmapkts = qlen * @@Weight + @ewmapkts * (1 - @@Weight) |
| 265 | end |
| 266 | @last = ts |
| 267 | end |
| 268 | end |
| 269 | sleep 5 |
| 270 | end |
| 271 | end |
| 272 | |
| 273 | def averages |
| 274 | a = nil |
| 275 | @lock.synchronize do |
| 276 | a = [@ewmabytes, @ewmapkts] |
| 277 | end |
| 278 | return a |
| 279 | end |
| 280 | end |
| 281 | }}} |
| 282 | In the above code, function ''averages'' will return the weighted average number of bytes seen in the corresponding node, as well as the weighted average queue depth in terms of number of bytes seen in the corresponding node. [[BR]] |
| 283 | Here is some example code that makes use of this class: |
| 284 | {{{ |
| 285 | @collectors = [DataCollector.new($leftip, @leftport), |
| 286 | DataCollector.new($rightip, @rightport)] |
| 287 | @collectors.each do |collector| |
| 288 | Thread.new(collector) do |c| |
| 289 | c.run |
| 290 | end |
| 291 | end |
| 292 | |
| 293 | left_monitor_value = @collectors[0].averages |
| 294 | right_monitor_value = @collectors[1].averages |
| 295 | #left_monitor_value[0] shows the average number of bytes seen on the left node |
| 296 | #left_monitor_value[1] shows the average number of queued packets on the left node |
| 297 | }}} |
| 298 | |
| 299 | '''Question: Implement your load-balancer.rb and display the number of bytes and queue length on both left and right node when a decision is made'''[[BR]] |
| 300 | '''A sample output should be as follows: [[BR]]''' |
| 301 | {{{ |
| 302 | left: 261315722.691471 bytes, Q Depth: 874380.631071448 packets |
| 303 | right: 445408379.683936 bytes, Q Depth: 642438.535302339 packets |
| 304 | so this new flow goes left. Total number of flows on the left: 1 |
| 305 | }}} |
| 306 | |
| 307 | |
| 308 | |
| 309 | '''Hints: Want to get the complete load-balancer.rb? ask your instructor or visit here (you need a password to get it), or send an email (the solution code may be full of bugs, feel free to tweak it and report bugs/ask questions)''' [[BR]] |