[ Transport ]
Ns2 에서는 agent 개념으로 설명
패킷 생성, 전송, 수신 구현
1. TCP
지원 프로토콜 (교재 349P 참고/ 10.3)
1.1 이용 방법
-
에이전트 생성
- Set tcp [new Agent/TCP] # 패킷 송신 에이전트를 변수 tcp로 지정
_ Agent/TCP - a "tahoe" TCP sender
_ Agent/TCP/Reno - a "Reno" TCP sender
_ Agent/TCP/Newreno - Reno with a modification
_ Agent/TCP/Sack1 - TCP with selective repeat (follows RFC2018)
_ Agent/TCP/Vegas - TCP Vegas
_ Agent/TCP/Fack - Reno TCP with "forward acknowledgment"
- Set tcpsink [new Agent/TCPSink] # 패킷 수신 에이전트를 변수 tcpsink로 지정
_ Agent/TCPSink - TCP sink with one ACK per packet
_ Agent/TCPSink/DelAck - TCP sink with configurable delay per ACK
_ Agent/TCPSink/Sack1 - selective ACK sink (follows RFC2018)
_ Agent/TCPSink/Sack1/DelAck - Sack1 with DelAck
- Set tcp [new Agent/TCP] # 패킷 송신 에이전트를 변수 tcp로 지정
-
에이전트와 노드 결합
- $ns attach-agent $n0 $tcp #n0 노드에 tcp에이전트 결합
- $ns attach-agent $n3 $sink #n3 노드에 sink에이전트 결합
-
에이전트끼리 연결
- $ns connect $tcp $sink #tcp 에이전트와 sink에이전트 연결
* Agent/TCP 와 Agent/TCPSink 한 쌍으로 설정 해야 함(교재 : 373p)
1.2 설정
[방법 1: simple configuration]
- 에이전트 설정
set ns [new Simulator] set node1 [$ns node] set node2 [$ns node] set tcp1 [$ns create-connection TCP $node1 TCPSink $node2 42] $tcp set window_ 50 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ns at 0.0 "$ftp start" |
* set tcp1 [$ns create-connection TCP $node1 TCPSink $node2 42]
- create-connection 함수의 의미
- TCP : 송신 에이젼트
- $node1 : 송신 노드 (souce node)
- TCPSink : 수신 에이젼트
- $node2 : 수신 노드
-
42 : flow ID
-
create-connection함수의 동작 순서
- 두 에이전트 생성, 에이전트의 flow ID필드 설정
- 송신 에이전트와 수신 에이전트를 알맞은 노드에 결합 시킨다
- 에이전트 끼리 연결 한다.(송수신의 각 포트, 주소 설정)
- create-connection 함수는 최종 결과값을 송신 에이전트가 생성될 때 사용한 이름인 tcp1로 반환 한다.
-
TDP 데이터 소스(Tcp Data Source)
-데이터 생성모듈 ex) FTP, Telnet
[방법 2: 파라미터 직접 작성]
파라미터 (변수)
클래스 변수 : 전체 에이전트 값 변함 (ex: Agent/TCP set window_ 100)
인스턴스변수 : 해당 에이전트만 변함 (ex : $tcp set window_ 2.0 )
Agent/TCP set window_ 20 ; # max bound on window size |
# set up TCP-level connections
$sink listen ; # will figure out who its peer is
$src set window_ 100;
The creation of the FullTcp agent is similar to the other agents, but the sink is placed in a listening state by the listen method. Because a handle to the receiving side is required in order to make this call, the create-connection call used above cannot be used.
TCP 연결 예제 TCL
$ns_ attach-agent $node_(s1) $tcp ; # bind src to node
$tcp set fid_ 0 ; # set flow ID field
set ftp [new Application/FTP] ; # create ftp traffic
$ftp attach-agent $tcp ; # bind ftp traffic to tcp agent
set sink [new Agent/TCPSink] ; # create tcpsink agent
$ns_ attach-agent $node_(k1) $sink ; # bind sink to node
$sink set fid_ 0 ; # set flow ID field
$ns_ connect $ftp $sink ; # active connection src to sink
$ns_ at $start-time "$ftp start" ; # start ftp flow
2. UDP
Agent/UDP와 agent/NULL을 한 쌍으로 함
[ Application ]
패킷 보내기
파라미터 정보 ./ns/tcl/lib/ns-default.tcl
CBR의 정보 : 교재 413p
(교재 : 배성수, "네트워크 시뮬레이터", 세화,2005)
1. Exponential
Exponential On/Off An Exponential On/Off object is embodied in the OTcl class Application/Traffic/Exponential. The
member variables that parameterize this object are:
packetSize_ the constant size of the packets generated
burst_time_ the average "on" time for the generator
idle_time_ the average "off" time for the generator
rate_ the sending rate during "on" times
Hence a new Exponential On/Off traffic generator can be created and parameterized as follows:
$e set packetSize_ 210
$e set burst_time_ 500ms
$e set idle_time_ 500ms
$e set rate_ 100k
NOTE: The Exponential On/Off generator can be configured to behave as a Poisson process by setting the variable burst_time_ to 0 and the variable rate_ to a very large value. The C++ code guarantees that even if the burst time is zero, at least one packet is sent. Additionally, the next interarrival time is the sum of the assumed packet transmission time (governed by the variable rate_) and the random variate corresponding to idle_time_. Therefore, to make the first term in the sum very small, make the burst rate very large so that the transmission time is negligible compared to the typical idle times.
2. CBR
A CBR object is embodied in the OTcl class Application/Traffic/CBR. The member variables that parameterize this
object are:
rate_ the sending rate
interval_ (Optional) interval between packets
packetSize_ the constant size of the packets generated
random_ flag indicating whether or not to introduce random "noise" in the scheduled departure times (default is off)
maxpkts_ the maximum number of packets to send (default is (228)
Hence a new CBR traffic generator can be created and parameterized as follows:
$e set packetSize_ 48
$e set rate_ 64Kb
$e set random_ 1
The setting of a CBR object's rate_ and interval_ are mutually exclusive (the interval between packets is maintained as an interval variable in C++, and some example ns scripts specify an interval rather than a rate). In a simulation, either a rate or an interval (but not both) should be specified for a CBR object.
-예제 ?
set sink [new Agent/UDP]
$ns_ attach-agent $node_(s1) $src
$ns_ attach-agent $node_(k1) $sink
$ns_ connect $src $sink
set e [new Application/Traffic/Exponential]
$e attach-agent $src
$e set packetSize_ 210
$e set burst_time_ 500ms
$e set idle_time_ 500ms
$e set rate_ 100k
$ns_ at 0.0 "$e start"
[Tips]
tr파일로 그래프 그리기
raw2xg ?a xxx.tr > xxx.out
xgraph xxx.out
nam. Tr. 파일 일괄 삭제 하는 스크립트 : Makefile 로 저장하기
[code type=c]
default: clean
clean:
rm -f *~ *.tr *.nam
[/code]
정리 : 2006.12.11 by 임헌정
http://www.4ellene.net
'Network > Ns2_Lecture' 카테고리의 다른 글
Implementing a New Manet Unicast Routing Protocol in NS2 Version 0.2 (0) | 2009.01.18 |
---|---|
NS2 - 무선환경 시뮬레이션 파라메터 설명 (0) | 2009.01.18 |
network components, ns by example (0) | 2009.01.18 |
NS by Example - Network Components (0) | 2009.01.18 |
802.11 MAC code in NS-2 (version 2.28) (0) | 2009.01.18 |