304 | | Add the script below to the new file, advOF-script.rb and click on the save icon at the top of the column. |
305 | | {{{ |
306 | | |
307 | | |
308 | | defApplication('oml:app:trace', 'trace') do |app| |
309 | | |
310 | | app.version(2, 10, 0) |
311 | | app.shortDescription = 'Packet capture' |
312 | | app.description = %{'trace' uses libtrace to capture packets matching the |
313 | | BPFilter, and report various header (IP, TCP, UDP, Radiotap,...) fields through |
314 | | OML. |
315 | | |
316 | | Note The pktid field in all MPs can be used to link information about the |
317 | | multiple protocols encapsulated in the same packet, even in cases where multiple |
318 | | packets have been received at the same time, which renders the timestamp field |
319 | | useless as an identifier. |
320 | | } |
321 | | app.path = "/usr/bin/trace" |
322 | | |
323 | | app.defProperty('filter', 'Filter expression BPFEXP', '-f', |
324 | | :type => :string, :mnemonic => 'f') |
325 | | app.defProperty('snaplen', 'Snarf Bytes of data from each packet', '-s', |
326 | | :type => :int, :unit => 'Bytes', :mnemonic => 's') |
327 | | app.defProperty('promisc', 'Put the interface into promiscuous mode', '-p', |
328 | | :type => 'boolean', :mnemonic => 'p') |
329 | | app.defProperty('interface', 'Interface to trace', '-i', |
330 | | :type => :string, :mnemonic => 'i', :default => '"eth0"') |
331 | | app.defProperty('radiotap', 'Enable radiotap', '-r', |
332 | | :type => 'boolean', :mnemonic => 'r') |
333 | | app.defProperty('config', 'config file to follow', '--oml-config', |
334 | | :type => :string, :default => '"/tmp/monitor/conf.xml"') |
335 | | |
336 | | |
337 | | app.defMeasurement("ip") do |m| |
338 | | m.defMetric('pktid', :int, ' internal packet ID to link MPs') |
339 | | m.defMetric('ip_tos', :int, ' Type of Service') |
340 | | m.defMetric('ip_len', :int, ' Total Length') |
341 | | m.defMetric('ip_id', :int, ' Identification') |
342 | | m.defMetric('ip_off', :int, ' IP Fragment offset (and flags)') |
343 | | m.defMetric('ip_ttl', :int, ' Time to Live') |
344 | | m.defMetric('ip_proto', :int, ' Protocol') |
345 | | m.defMetric('ip_sum', :int, ' Checksum') |
346 | | m.defMetric('ip_src', :string, ' Source Address') |
347 | | m.defMetric('ip_dst', :string, ' Destination Address') |
348 | | m.defMetric('ip_sizeofpacket', :int, ' Size of the Packet') |
349 | | m.defMetric('ip_ts', :float, ' timestamp of the measurement') |
350 | | end |
351 | | |
352 | | app.defMeasurement("tcp") do |m| |
353 | | m.defMetric('pktid', :int, ' internal packet ID to link MPs') |
354 | | m.defMetric('tcp_source', :int, ' Source Port') |
355 | | m.defMetric('tcp_dest', :int, ' Destination Port') |
356 | | m.defMetric('tcp_seq', :int, ' TCP sequence Number') |
357 | | m.defMetric('tcp_ack_seq', :int, ' Acknowledgment Number') |
358 | | m.defMetric('tcp_window', :int, ' Window Size') |
359 | | m.defMetric('tcp_checksum', :int, ' Checksum') |
360 | | m.defMetric('tcp_urgptr', :int, ' Urgent Pointer') |
361 | | m.defMetric('tcp_packet_size', :int, ' Size of the Packet') |
362 | | m.defMetric('tcp_ts', :float, ' timestamp of the measurement') |
363 | | end |
364 | | |
365 | | end |
366 | | |
367 | | |
368 | | |
369 | | defApplication('nmetrics_app', 'nmetrics') do |app| |
370 | | |
371 | | app.version(2, 10, 0) |
372 | | app.shortDescription = 'Monitoring node statistcs' |
373 | | app.description = %{'nmetrics' is monitoring various node specific statistics, |
374 | | such as CPU, memory and network usage and reports them through OML. |
375 | | } |
376 | | app.path = "/usr/bin/nmetrics" |
377 | | |
378 | | app.defProperty('interface', 'Report usage for the specified network interface (can be used multiple times)', '-i', |
379 | | :type => :string, :mnemonic => 'i', |
380 | | :default => '"eth0"', :var_name => 'if_name') |
381 | | app.defProperty('sample-interval', 'Time between consecutive measurements', '-s', |
382 | | :type => :int, :unit => 'seconds', :mnemonic => 's', |
383 | | :var_name => 'sample_interval') |
384 | | |
385 | | app.defMeasurement("network") do |m| |
386 | | m.defMetric('name', :string) |
387 | | m.defMetric('rx_packets', :int) |
388 | | m.defMetric('rx_bytes', :int) |
389 | | m.defMetric('rx_errors', :int) |
390 | | m.defMetric('rx_dropped', :int) |
391 | | m.defMetric('rx_overruns', :int) |
392 | | m.defMetric('rx_frame', :int) |
393 | | m.defMetric('tx_packets', :int) |
394 | | m.defMetric('tx_bytes', :int) |
395 | | m.defMetric('tx_errors', :int) |
396 | | m.defMetric('tx_dropped', :int) |
397 | | m.defMetric('tx_overruns', :int) |
398 | | m.defMetric('tx_collisions', :int) |
399 | | m.defMetric('tx_carrier', :int) |
400 | | m.defMetric('speed', :int) |
401 | | end |
402 | | |
403 | | app.defMeasurement("procs") do |m| |
404 | | m.defMetric('cpu_id', :int) |
405 | | m.defMetric('total', :int) |
406 | | m.defMetric('sleeping', :int) |
407 | | m.defMetric('running', :int) |
408 | | m.defMetric('zombie', :int) |
409 | | m.defMetric('stopped', :int) |
410 | | m.defMetric('idle', :int) |
411 | | m.defMetric('threads', :int) |
412 | | end |
413 | | |
414 | | app.defMeasurement("proc") do |m| |
415 | | m.defMetric('pid', :int) |
416 | | m.defMetric('start_time', :int) |
417 | | m.defMetric('user', :int) |
418 | | m.defMetric('sys', :int) |
419 | | m.defMetric('total', :int) |
420 | | end |
421 | | end |
422 | | #COMMENT |
423 | | defPrototype("system_monitor") do |p| |
424 | | p.name = "System Monitor" |
425 | | p.description = "A monitor that reports stats on the system's resource usage" |
426 | | p.defProperty('monitor_interface', 'Monitor the interface usage', 'eth1') |
427 | | p.defProperty('sample-interval', 'sample-interval', '1') |
428 | | |
429 | | p.addApplication("nmetrics_app") do |a| |
430 | | a.bindProperty('interface', 'monitor_interface') |
431 | | a.bindProperty('sample-interval', 'sample-interval') |
432 | | a.measure('network', :samples => 1) |
433 | | end |
434 | | end |
435 | | |
436 | | |
437 | | |
438 | | |
439 | | |
440 | | ###### Change the following to the correct interfaces ###### |
441 | | left = 'eth1' |
442 | | right = 'eth2' |
443 | | ###### Change the above to the correct interfaces ###### |
444 | | |
445 | | ##definition of Sender, Receiver and Monitors |
446 | | defProperty('source','outside','ID of sender node') |
447 | | defProperty('sink', 'inside', "ID of receiver node") |
448 | | defProperty ('balancer', 'switch', "ID of the load balancer") |
449 | | defProperty('graph', true, "Display graph or not") |
450 | | |
451 | | defGroup('Sender', property.source) do |node| |
452 | | end |
453 | | |
454 | | defGroup('Receiver', property.sink) do |node| |
455 | | end |
456 | | #measure the total bytes sent out and the total throughput on left path |
457 | | defGroup('Monitor', property.balancer) do |node| |
458 | | node.addApplication("oml:app:trace") do |app| |
459 | | app.setProperty("interface", left) |
460 | | app.setProperty("config", "/tmp/monitor/conf.xml") |
461 | | app.measure("tcp", :samples => 1) |
462 | | end |
463 | | options = { 'sample-interval' => 1, 'monitor_interface' => left } |
464 | | node.addPrototype("system_monitor", options) |
465 | | end |
466 | | #measure the total bytes sent out and the total throughput on right path |
467 | | defGroup('Monitor1', property.balancer) do |node| |
468 | | node.addApplication("oml:app:trace") do |app| |
469 | | app.setProperty("interface", right) |
470 | | app.setProperty("config", "/tmp/monitor/conf.xml") |
471 | | app.measure("tcp", :samples => 1) |
472 | | end |
473 | | options = { 'sample-interval' => 1, 'monitor_interface' => right } |
474 | | node.addPrototype("system_monitor", options) |
475 | | end |
476 | | |
477 | | |
478 | | |
479 | | ##experiment starts here## |
480 | | onEvent(:ALL_UP_AND_INSTALLED) do |event| |
481 | | info "starting the monitor" |
482 | | group('Monitor').startApplications |
483 | | group('Monitor1').startApplications |
484 | | |
485 | | info "Starting the Receiver" |
486 | | group('Receiver').exec("iperf -s") |
487 | | wait 2 |
488 | | |
489 | | #-------------------------------------------------------------------- |
490 | | #info "***********starting Load Balancer************" |
491 | | #group('Monitor').exec("/opt/trema-trema-f995284/trema run /root/load-balancer.rb > /tmp/lb.tmp") |
492 | | #wait 2 |
493 | | #info "connecting switch to load balancer controller" |
494 | | #group('Monitor').exec("ovs-vsctl set-controller br0 tcp:127.0.0.1 ptcp:6634:127.0.0.1") |
495 | | #wait 5 |
496 | | |
497 | | $i = 1 |
498 | | $exp_time = 100 |
499 | | $interval = 5 |
500 | | $total = $exp_time / $interval |
501 | | while $i <= $total do |
502 | | info "Starting Sender " + $i.to_s |
503 | | group('Sender').exec("iperf -c 10.10.10.2 -t "+ ($exp_time-$i*$interval).to_s) |
504 | | wait $interval |
505 | | $i += 1 |
506 | | end |
507 | | |
508 | | info "All applications started..." |
509 | | wait $interval |
510 | | |
511 | | #info "************stoping Load Balancer***************" |
512 | | #group('Monitor').exec("killall ruby") |
513 | | #group('Monitor').exec("rm /opt/trema-trema-f995284/tmp/pid/LoadBalancer.pid") |
514 | | #info "remove switch-to-controller connection" |
515 | | #group('Monitor').exec("ovs-vsctl del-controller br0") |
516 | | |
517 | | info "All applications stopped." |
518 | | allGroups.stopApplications |
519 | | Experiment.done |
520 | | end |
521 | | |
522 | | |
523 | | ##define the graphs that we want to display## |
524 | | defGraph 'Cumulated number of Bytes' do |g| |
525 | | g.ms('network').select(:oml_ts_server, :tx_bytes, :oml_sender_id) |
526 | | g.caption "Total Bytes" |
527 | | g.type 'line_chart3' |
528 | | g.mapping :x_axis => :oml_ts_server, :y_axis => :tx_bytes, :group_by => :oml_sender_id |
529 | | g.xaxis :legend => 'timestamp', :ticks => {:format => 's'} |
530 | | g.yaxis :legend => 'sent Bytes', :ticks => {:format => 'Byte'} |
531 | | end |
532 | | |
533 | | defGraph 'TCP Throughput Bytes-per-Second' do |g| |
534 | | g.ms('tcp').select(:oml_ts_server, :tcp_throughput_sum, :oml_sender_id) |
535 | | g.caption "TCP throughput" |
536 | | g.type 'line_chart3' |
537 | | g.mapping :x_axis => :oml_ts_server, :y_axis => :tcp_throughput_sum, :group_by => :oml_sender_id |
538 | | g.xaxis :legend => 'timestamp', :ticks => {:format => 's'} |
539 | | g.yaxis :legend => 'throughput', :ticks => {:format => 'Bytes/s'} |
540 | | end |
541 | | |
542 | | }}} |