empaper2.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
源码类别:

通讯编程

开发平台:

Visual C++

  1. set stoptime 200.0 ; # simulation end time (seconds)
  2. set owdelay 10ms ; # 1-way delay
  3. set virtaddr "128.32.130.59"
  4. #set website "169.229.60.105"
  5. set website "128.32.130.33"
  6. set ns [new Simulator] ; # create simulator object
  7. $ns use-scheduler RealTime ; # specify the real-time sync'd scheduler
  8. set bpf1 [new Network/Pcap/Live]; # live traffic -- read IP pkts
  9. set bpf2 [new Network/Pcap/Live]; # live traffic -- read IP pkts
  10. $bpf1 set promisc_ true          ; # use promiscuous mode
  11. $bpf2 set promisc_ true          ; # use promiscuous mode
  12. $bpf1 open readonly fxp0 ; # specify interface
  13. $bpf2 open readonly fxp0 ; # specify interface
  14. set ipnet [new Network/IP]      ; # live traffic -- write IP pkts
  15. $ipnet open writeonly
  16. set myrealaddr [$bpf1 netaddr]
  17. $bpf1 filter "tcp and src $myrealaddr and dst $virtaddr"; #
  18. $bpf2 filter "tcp and dst $virtaddr and not src $myrealaddr";
  19. set pfa1 [new Agent/Tap]
  20. set pfa2 [new Agent/Tap]
  21. set ipa [new Agent/Tap]
  22. set outgoingNAT [new Agent/NatAgent/TCPSrcDest]
  23. set incomingNAT [new Agent/NatAgent/TCPSrcDest]
  24. $outgoingNAT source $virtaddr
  25. $outgoingNAT destination $website
  26. $incomingNAT source $virtaddr
  27. $incomingNAT destination $myrealaddr
  28. $pfa1 network $bpf1       ; # associate pf net object w/tap agent
  29. $pfa2 network $bpf2       ; # associate pf net object w/tap agent
  30. $ipa network $ipnet     ; # associate ip net object w/tap agent
  31. # create topology in simulator
  32. set node0 [$ns node]
  33. set node1 [$ns node]
  34. set node2 [$ns node]
  35. $ns simplex-link $node0 $node2 100Mb $owdelay DropTail
  36. $ns simplex-link $node2 $node1 100Mb $owdelay DropTail
  37. # place agents in topology
  38. $ns attach-agent $node0 $pfa1; #        packet filter agent
  39. $ns attach-agent $node0 $pfa2; #        packet filter agent
  40. $ns attach-agent $node1 $ipa; # ip agent (for sending)
  41. $ns attach-agent $node2 $outgoingNAT
  42. $ns attach-agent $node2 $incomingNAT
  43. $ns simplex-connect $pfa1 $outgoingNAT
  44. $ns simplex-connect $pfa2 $incomingNAT
  45. $ns simplex-connect $outgoingNAT $ipa
  46. $ns simplex-connect $incomingNAT $ipa
  47. puts "[$outgoingNAT set dst_]"
  48. $ns gen-map
  49. $ns run ; # start emulation