62
NS Tutorial PMIPv6 Implementation in NS HyonYoung Choi ([email protected])

NS Tutorial(PMIP) (1)

Embed Size (px)

Citation preview

Page 1: NS Tutorial(PMIP) (1)

NS TutorialPMIPv6 Implementation in NS

HyonYoung Choi ([email protected])

Page 2: NS Tutorial(PMIP) (1)

목차•NS 기초•PMIPv6 Implementation

Page 3: NS Tutorial(PMIP) (1)
Page 4: NS Tutorial(PMIP) (1)

Tcl 와 C++ 의 연관관계• Tcl Object 와 C++ Object 의 매핑

▫일반적으로 Tcl Object 당 C++ Object 가 존재▫TclClass 가 Tcl 에서 C++ object 를 만들 수

있도록 해줌 TclClass 의 생성자 인수가 Tcl 에서 사용가능한 Object

이름set mag [new Agent/PMIPv6/MAG]

static class MAGAgentClass : public TclClass {public: MAGAgentClass() : TclClass("Agent/PMIPv6/MAG") {} TclObject* create(int, const char*const*) { return (new MAGAgent()); }} class_magagent;

class MAGAgent : public PMIPv6Agent {public: MAGAgent();……};

Page 5: NS Tutorial(PMIP) (1)

NS 의 함수 (1/4)• 함수의 정의

▫Tcl: instproc 를 사용하여 정의

▫C++: TclObject class 의 command 함수 overriding 후 if-else-if 로 string match

Classifier/Addr/PMIPv6Dest instproc install {dst target} { $self instvar classifier_ $classifier_ install $dst $target}

int MAGAgent::command(int argc, const char*const* argv) { if(argc==3) { if(strcmp(argv[1], "new-mn") == 0) { …… return TCL_OK; } else if(strcmp(argv[1], "set-lmaa") == 0) { …… return (PMIPv6Agent::command(argc, argv));}

Page 6: NS Tutorial(PMIP) (1)

NS 의 함수 (2/4)

•Tcl 함수와 C++ 함수의 장단점장점 단점

Tcl 함수 Type 이 없어 변수처리가 쉽다배열 , 리스트 , 타이머 처리가 용이하다

변수 값에 의한 버그 발생C++ 보다 실행속도가 늦다

C++ 함수 Object 접근이 쉽다Tcl 보다 실행속도가 빠르다

Object 상호참조로 구조가 복잡해질 수 있다 .

Page 7: NS Tutorial(PMIP) (1)

NS 의 함수 (3/4)• Tcl 함수와 C++ 함수의 상호접근

▫함수 호출의 우선순위 : Tcl > C++ Tcl 의 함수에서 찾은 뒤 없으면 C++ 의 command 함수

호출▫Tcl 과 C++ 에 같은 이름의 함수가 있는 경우

Tcl 의 함수 호출 : 일반적인 함수 호출 C++ 의 함수 호출 : 함수이름 앞에 “ cmd” 를 추가Classifier/Addr/PMIPv6Dest instproc clear { dst } {

$self instvar classifier_ $classifier_ clear $dst}Classifier/Addr/PMIPv6Dest instproc clear-by-dest { addr } { $self cmd clear $addr}

Page 8: NS Tutorial(PMIP) (1)

NS 의 함수 (4/4)

•Tcl 함수와 C++ 함수의 상호접근 (cont’d)▫C++ 에서 Tcl 함수 호출

Tcl::eval, Tcl::evalf 함수 사용

▫C++ 에서 Tcl 함수의 결과값 얻기 Tcl::result 함수 사용

▫C++ 함수에서 Tcl 로 결과값 반환 (return) Tcl::resultf 함수 사용

Tcl& tcl = Tcl::instance(); tcl.evalf("%s setup-route %ld %ld", name(), bule->mn_prefix(), bule->lmaa());

tcl.evalf ("%s getRXThresh",netif_->name()); RXThreshold_ = atof (tcl.result());

if (strcmp(argv[1], "ifq") == 0) { tcl.resultf("%s", ifq_->name()); return (TCL_OK); }

Page 9: NS Tutorial(PMIP) (1)

새로운 packet type 만들기 (1/4)• 1. Packet 헤더 작성

▫offset_, offset(), access(Packet *p) 작성 ( 필수 )▫HDR_XXX define 작성 ( 옵션 )▫offset_ 이 static 이므로 C++ 소스 파일에 선언#define HDR_PMIPv6((p) ((struct hdr_pmipv6*)(p)->access(hdr_pmipv6::offset_))struct hdr_pmipv6 { ……( 패킷 헤더의 필드들 )

static int offset_; inline static int& offset() { return offset_; } inline static hdr_pmipv6* access(Packet* p) { return (hdr_pmipv6*) p->access(offset_); }};int hdr_pmipv6::offset_;

Page 10: NS Tutorial(PMIP) (1)

새로운 packet type 만들기 (2/4)• 2. PacketHeaderClass 작성

▫Packet Manager 용 class 작성

• 3. ns-packet.tcl 수정 (ns-2.29/tcl/lib/)▫PacketHeaderClass 생성자의 이름과 일치해야 함

static class PMIPv6HeaderClass : public PacketHeaderClass {public: PMIPv6HeaderClass() : PacketHeaderClass("PacketHeader/PMIPv6", sizeof(hdr_pmipv6)) { bind_offset(&hdr_pmipv6::offset_); }} class_pmipv6hdr;

foreach prot {…… PMIPv6} { add-packet-header $prot}

Page 11: NS Tutorial(PMIP) (1)

새로운 packet type 만들기 (3/4)• 4. packet.h 수정 (ns-2.29/common/)

▫ enum packet_t 의 PT_NTYPE 전에 넣음

▫ name_ 작성 : trace 에 표시되는 패킷 type

enum packet_t {…… //PMIP6: type PT_PBU, PT_PBACK, PT_NTYPE // This MUST be the LAST one};

p_info() {…… name_[PT_PBU]="pbu"; name_[PT_PBACK]="pba"; name_[PT_NTYPE]= "undefined"; }

Page 12: NS Tutorial(PMIP) (1)

새로운 packet type 만들기 (4/4)• 패킷 생성

▫allockpkt 함수 사용▫hdr_cmn 정보 반드시 채울 것

size: 실제 전송되는 총 패킷 크기 ptype: packet type

Packet *p = allocpkt(); hdr_cmn *hdrc = HDR_CMN(p); hdr_ip *iph = HDR_IP(p); hdr_pmipv6 *h = HDR_PMIPv6(p); hdrc->size() = IPv6_HEADER_SIZE; hdrc->ptype() = PT_PBU; hdrc->size() += PBU_SIZE; iph->saddr() = proxy_coa; iph->sport() = port();……

Page 13: NS Tutorial(PMIP) (1)

List 관리 – Tcl (1/2)

•배열로 처리 (index 에 문자도 가능 )•중복처리를 쉽게 할 수 있음•간단한 형태만 가능•1. List 추가

▫덮어 쓰는 경우는 바로 추가▫이미 존재하면 에러인 경우는 이미 있는지 검사

info exists 사용Node instproc listadd {index value} { $self instvar List_ if { ! [info exists List_($index)] || $List_($index)==“”} { set List_($index) $value }}

Page 14: NS Tutorial(PMIP) (1)

List 관리 – Tcl (2/2)

•2. List 제거▫존재 하는 경우 “”로 만들거나 unsetNode instproc listdel {index} { $self instvar List_ if { [info exists List_($index)] && $List_($index)!=“”} { set List_($index) “” unset List_($index) }}

Page 15: NS Tutorial(PMIP) (1)

List 관리 - C++ (1/2)• List 관련 매크로 활용• 1. LIST_HEAD 정의

▫데이터 클래스와 그에 연결되는 head 정의

• 2. 리스트 각 entry 내용 정의▫insert_entry. next_entry, remove_entry, link

정의

class BULEntry;LIST_HEAD(bulEntry, BULEntry);

class BULEntry {……public: inline void insert_entry(struct bulEntry *head) { LIST_INSERT_HEAD(head, this, link); } BULEntry* next_entry(void) const { return link.le_next; } inline void remove_entry() { LIST_REMOVE(this, link); }

protected: LIST_ENTRY(BULEntry) link;};

Page 16: NS Tutorial(PMIP) (1)

List 관리 - C++ (2/2)

•3. List 사용▫List 변수 정의

▫List 에 추가

▫List 에서 찾기

class MAGAgent : public PMIPv6Agent {……

struct bulEntry bul_list_;

void MAGAgent::process_new_mn(int32_t mn_id) {…… bule->insert_entry(&bul_list_);

BULEntry *MAGAgent::find_bule(int32_t mn_id) { for(BULEntry *bule=bul_list_.lh_first; bule; bule=bule->next_entry()) { if(bule->mn_id() == mn_id) return bule; } return NULL;}

Page 17: NS Tutorial(PMIP) (1)

Timer 관리 - Tcl

•ns simulator 의 at 함수 활용•1. timeout 시 실행될 함수 정의

•2. Timer 시작과 중단

Node instproc record {} { set ns [Simulator instance]……..}

Node instproc start { mnaddr } { $self instvar RTimer_ set ns [Simulator instance] set now [$ns now] if {![info exists RTimer_($mnaddr)] || $RTimer_($mnaddr) == ""} { $ns at [expr $now + 1.0] “$self record” }}

Node instproc stop { mnaddr } { $self instvar RTimer_ set ns [Simulator instance] if {[info exists RTimer_($mnaddr)] && $RTimer_($mnaddr) != ""} { $ns cancel $RTimer_($mnaddr) set Rtimer_($mnaddr) “” }}

Page 18: NS Tutorial(PMIP) (1)

Timer 관리 – C++ (1/2)

•TimerHandler 를 사용하여 구현•1. TimerHandler 를 상속한 클래스 정의

▫생성자에 호출할 정보를 넣도록 작성▫expire 함수를 반드시 overridingclass BindingTimer : public TimerHandler {public: BindingTimer(PMIPv6Agent *pagent, void *data): TimerHandler() { pagent_ = pagent; data_ = data; }protected: PMIPv6Agent *pagent_; void *data_;

void expire(Event *);};

Page 19: NS Tutorial(PMIP) (1)

Timer 관리 – C++ (2/2)

•2. expire 함수 정의▫Timer 를 설정해 놓으면 지정된 시간 이후

호출되는 함수▫생성자로 받은 정보를 사용해 원하는 작업 수행

•3. timer 시작과 중단 하기▫resched 함수와 cancel 함수 사용

void BindingTimer::expire(Event *) { pagent_->BindingTimeout(data_);}

bule->BULTimer_.resched(1.0);

bule->BULTimer_.cancel ();

Page 20: NS Tutorial(PMIP) (1)
Page 21: NS Tutorial(PMIP) (1)

PMIPv6 Objects (1/2)• PacketHeader/PMIPv6 (struct hdr_pmipv6)

▫ PBU, PBACK 패킷을 위한 헤더• PacketHeader/IP6Encap (struct hdr_ip6encap)

▫ IPv6-in-IPv6 패킷을 위한 헤더• Agent/PMIPv6 (class PMIPv6Agent)

▫ LMA 와 MAG 의 상위 클래스• Agent/PMIPv6/LMA (class LMAAgent)

▫ LMA Agent• Agent/PMIPv6/MAG (class MAGAgent)

▫ MAG Agent

Page 22: NS Tutorial(PMIP) (1)

PMIPv6 Objects (2/2)• PMIPv6Encapsulator (class

PMIPv6Encapsulator)▫IPv6-in-IPv6 Encapsulator

• Classifier/Addr/PMIPv6Src (class PMIPv6Src)▫Source address based routing

• Classifier/Addr/PMIPv6Dest (class PMIPv6Dest)▫Destination address routing

• Classifier/Addr/PMIPv6Decapsulator (class PMIPv6Decapsulator)▫IPv6-in-IPv6 Decapsulator

Page 23: NS Tutorial(PMIP) (1)

PMIPv6 example script

Page 24: NS Tutorial(PMIP) (1)

General Initialization• Hierarchical routing

▫MN 패킷이 LMA 로 routing 되도록 하기 위함

•Wireless configuration

# set up for hierarchical routing (needed for routing over a basestation)$ns node-config -addressType hierarchicalAddrParams set domain_num_ 5 ;# domain numberAddrParams set cluster_num_ {1 1 1 1 1}AddrParams set nodes_num_ {1 2 1 1 1}

# Parameter for wireless nodesset opt(chan) Channel/WirelessChannel ;# channel typeset opt(prop) Propagation/TwoRayGround ;# radio-propagation modelset opt(netif) Phy/WirelessPhy ;# network interface typeset opt(mac) Mac/802_11 ;# MAC typeset opt(ifq) Queue/DropTail/PriQueue ;# interface queue typeset opt(ll) LL ;# link layer typeset opt(ant) Antenna/OmniAntenna ;# antenna modelset opt(ifqlen) 50 ;# max packet in ifqset opt(adhocRouting) DSDV ;# routing protocol

Page 25: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (1/8)

•LMA▫LMA Node 생성 후 install-lma 함수 호출

주의사항 : duplex-link 호출 전에 install-lma 호출set lma [$ns node 1.0.0]

#attach Agent/PMIPv6/LMA to the LMAset lma_pm [$lma install-lma]#BE CAREFUL!. PMIPv6 agent must be installed before connecting link(duplex-link)$ns duplex-link $lma $router 100Mb $opt(dfLinkDelay) DropTail

Page 26: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (2/8)

•LMA (cont’d)▫install-lma 함수

Page 27: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (3/8)

•install-lma 함수Node instproc install-lma {} { $self instvar classifier_ decap_ dmux_ agents_ $self instvar pmip6_agent_ $self instvar dst_classifier_ old_classifier_ #attach pmip6 agent set lma [new Agent/PMIPv6/LMA] $self attach $lma [$lma set default_port_] set pmip6_agent_ $lma #attach dest classifier set old_classifier_ $classifier_ set dst_classifier_ [new Classifier/Addr/PMIPv6Dest] $dst_classifier_ set mask_ 0xffffffff $dst_classifier_ set shift_ 0 $dst_classifier_ defaulttarget $old_classifier_

Page 28: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (4/8)

•install-lma 함수 (cont’d) set nodetype [[Simulator instance] get-nodetype]

$self insert-entry [$self get-module $nodetype] $dst_classifier_ $dst_classifier_ install-by-dest 0 $old_classifier_

#attach decapsulator set decap_ [new Classifier/Addr/PMIPv6Decapsulator] $decap_ set mask_ 0xffffffff $decap_ set shift_ 0 $decap_ defaulttarget $dst_classifier_ lappend $agents_ $decap_ $dmux_ install [Simulator set PMIPv6_TUNNEL_PORT] $decap_ return $lma}

Page 29: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (5/8)• MAG

▫ NIST settings: bssid, channel, beacon 설정▫ install-mag 호출▫ set-lmaa 호출 : LMA Address 지정▫ 802.11 MAC 에 trigger 를 위한 설정

set mag1 [$ns node 3.0.0]$mag1 random-motion 0$mag1 set X_ 100.0$mag1 set Y_ 200.0$mag1 set Z_ 0.0

#NIST settingsset mag1_mac [$mag1 getMac 0]set mag1_addr [$mag1_mac id]$mag1_mac bss_id $mag1_addr$mag1_mac set-channel 1$mag1_mac enable-beacon

#install PMIPv6/MAG agent to the MAG1set mag1_pm [$mag1 install-mag]set lmaa [$lma node-addr]$mag1_pm set-lmaa [AddrParams addr2id $lmaa]

#setup 802.11 MAC to support MN ATTACH Event$mag1_mac set use_pmip6_ext_ 1$mag1_mac pmip6-agent $mag1_pm

$ns duplex-link $mag1 $router 100Mb $opt(dfLinkDelay) DropTail

Page 30: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (6/8)

•MAG (cont’d)

Page 31: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (7/8)

•install-mag 함수Node instproc install-mag {} { $self instvar classifier_ dmux_ agents_ ll_

$self instvar pmip6_agent_ $self instvar src_classifier_ old_classifier_ $self instvar decap_ set mag [new Agent/PMIPv6/MAG] $self attach $mag [$mag set default_port_] set pmip6_agent_ $mag #attach src classifier set old_classifier_ $classifier_

set src_classifier_ [new Classifier/Addr/PMIPv6Src] $src_classifier_ set mask_ 0xffffffff $src_classifier_ set shift_ 0 $src_classifier_ defaulttarget $old_classifier_

Page 32: NS Tutorial(PMIP) (1)

PMIPv6 Initialization (8/8)

•install-mag 함수 (cont’d) set nodetype [[Simulator instance] get-nodetype]

$self insert-entry [$self get-module $nodetype] $src_classifier_ $src_classifier_ install-by-src 0 $old_classifier_ #attach decap_ set decap_ [new Classifier/Addr/PMIPv6Decapsulator] $decap_ set mask_ 0xffffffff $decap_ set shift_ 0 lappend $agents_ $decap_ $dmux_ install [Simulator set PMIPv6_TUNNEL_PORT] $decap_

# LL points previous hier_classifier as up-target # we should change this to our classifier if {[info exists ll_(0)] && $ll_(0) != ""} { $ll_(0) up-target $src_classifier_ } return $mag}

Page 33: NS Tutorial(PMIP) (1)

Binding Update Process (1/3)

•Sending PBUMAGAgentMac802_11

new-mn/TCL

process_new_mn()-find_bule

command()

send_pbu()

PMIPv6Agent

create_pbu()

send()

Page 34: NS Tutorial(PMIP) (1)

Binding Update Process (2/3)

•Receiving PBU/Sending PBACKLMAAgentPMIPv6Agent

process_packet()

setup_route()

process_pbu()-find_bce()

setup-route/TCL-get-pmip6-encap/TCL

send_pback()

recv()

create_pback()

send()

Page 35: NS Tutorial(PMIP) (1)

Binding Update Process (3/3)

•Receiving PBACKMAGAgentPMIPv6Agent

process_packet()

setup_route()

process_pback()-find_bule()

setup-route/TCL-get-pmip6-encap/TCL

recv()

clear_route()

clear-route/TCL

bule_state: BUL_S_SETUP

bule_state: BUL_S_DELETE

Page 36: NS Tutorial(PMIP) (1)

Data Process (1/2)

•LMA MAGPMIPv6EncapsulatorPMIPv6Dest

recv()

classify()recv()

target_->recv()

PMIPv6Decapsulator

recv()find()

link->recv()

Page 37: NS Tutorial(PMIP) (1)

Data Process (2/2)

•MAG LMAPMIPv6EncapsulatorPMIPv6Src

recv()

classify()recv()

target_->recv()

PMIPv6Decapsulator

recv()find()

link->recv()

Page 38: NS Tutorial(PMIP) (1)

802.11 MAC Operation (1/5)

•802.11 MAC 에서 Layer 2 Trigger 발생MAGAgentMac802_11

new-mn/TCL

process_new_mn()-find_bule

command()

send_pbu()

PMIPv6Agent

create_pbu()

send()

Page 39: NS Tutorial(PMIP) (1)

802.11 MAC Operation (2/5)• 802.11 MAC 수정

▫class Mac802_11 (ns-2.29/mac/mac-802_11.h) use_pmip6_ext_: PMIPv6 용 L2 trigger 사용 pmip6_agent_: L2 trigger 를 전달할 PMIPv6 agent

▫pmip6-agent 함수 추가

class Mac802_11 : public Mac {…… //PMIPv6 int use_pmip6_ext_; Agent* pmip6_agent_; //End PMIPv6

int Mac802_11::command(int argc, const char*const* argv) {……else if (strcmp(argv[1], "pmip6-agent") == 0) { if(use_pmip6_ext_==0) return TCL_ERROR; pmip6_agent_ = (Agent *)TclObject::lookup(argv[2]); return TCL_OK; }

Page 40: NS Tutorial(PMIP) (1)

802.11 MAC Operation (3/5)• 802.11 MAC 수정 (cont’d)

▫802.11 MAC 에서 AP address 적용 버그 수정

▫Link 가 끊어졌을 때 자동으로 스캔하도록 수정

inline int Mac802_11::hdr_dst(char* hdr, int dst ) {…… //PMIPv6 if(dst != bss_id_) STORE4BYTE(&bss_id_, (dh->dh_3a)); //end PMIPv6

void Mac802_11::link_disconnect (link_down_reason_t reason) {…… //PMIPv6 if(!mih_) { //If disconnected, it automatically starts scanning Tcl& tcl = Tcl::instance(); tcl.evalf ("%s autoscan", name()); } //PMIPv6 end

Page 41: NS Tutorial(PMIP) (1)

802.11 MAC Operation (4/5)• 802.11 MAC 수정 (cont’d)

▫AP 를 발견하면 바로 연결되도록 수정void Mac802_11::nextScan () {…… //PMIPv6 if(!mih_) { BSSDescription *n;

n=scan_status_.resp->bssDesc_head.lh_first;

//store structure scan bssid/channel Vincent Gauthier channelIDAfterScan_[n->bss_id()] = n->channel(); link_connect(n->bss_id()); } //PMIPv6 end

Page 42: NS Tutorial(PMIP) (1)

802.11 MAC Operation (5/5)• Layer 2 Trigger 발생

▫AssocRes 메시지가 도착하면 시작▫PMIPv6 agent 의 new-mn 함수 호출void Mac802_11::recvACK(Packet *p) {…… //PMIPv6 if(use_pmip6_ext_) { if(pmip6_agent_) { Tcl& tcl = Tcl::instance(); tcl.evalf("%s new-mn %d", pmip6_agent_->name(), n->id()); } } //end PMIPv6

Page 43: NS Tutorial(PMIP) (1)

MAG Operation #1 (1/5)

•MAG 에서 L2 Trigger 처리 후 PBU 전송MAGAgentMac802_11

new-mn/TCL

process_new_mn()-find_bule

command()

send_pbu()

PMIPv6Agent

create_pbu()

send()

Page 44: NS Tutorial(PMIP) (1)

MAG Operation #1 (1/4)• new-mn 함수 이후 process_new_mn 호출

• process_new_mn 함수▫ Binding Update List 처리▫ BUL entry (bule)

PBU retransmission timer 마지막 PBU 저장 (pktPBU_)

int MAGAgent::command(int argc, const char*const* argv) {…… else if(argc==3) { if(strcmp(argv[1], "new-mn") == 0) { uint32_t id;

id = atoi(argv[2]); process_new_mn(id); return TCL_OK; }

Page 45: NS Tutorial(PMIP) (1)

MAG Operation #1 (2/4)

•process_new_mn 함수 (cont’d)void MAGAgent::process_new_mn(int32_t mn_id) { BULEntry *bule;

bule = find_bule(mn_id); if(!bule) { bule = create_bule(mn_id); bule->lmaa() = lma_addr_; bule->proxy_coa() = addr(); bule->lifetime() = binding_lifetime_; bule->insert_entry(&bul_list_); }

else { bule->BULTimer_.cancel(); if(bule->pktPBU_) { Packet::free(bule->pktPBU_); bule->pktPBU_ = 0; } }

bule->set_state(BUL_S_SETUP); bule->retry_count_ = 0;

send_pbu(bule);}

Page 46: NS Tutorial(PMIP) (1)

MAG Operation #1 (3/4)

•send_pbu 함수▫PMIPv6Agent 의 create_pbu 함수로 PBU

생성▫bule 에 생성된 PBU 를 저장하고 복사본 전송▫Retransmission timer 설정void MAGAgent::send_pbu(BULEntry *bule) { if(!bule->pktPBU_) { bule->pktPBU_ = create_pbu(bule->lmaa(), bule->mn_id(), bule->lifetime(), bule->proxy_coa()); }

send(bule->pktPBU_->copy(), 0);

//FIXME: adjust retransmit timeout (Random backoff??) bule->BULTimer_.resched(1.0);}

Page 47: NS Tutorial(PMIP) (1)

MAG Operation #1 (4/4)

•create_pbu 함수Packet *PMIPv6Agent::create_pbu( int32_t dst, int32_t mn_id, uint32_t lifetime, int32_t proxy_coa) { Packet *p = allocpkt(); hdr_cmn *hdrc = HDR_CMN(p); hdr_ip *iph = HDR_IP(p); hdr_pmipv6 *h = HDR_PMIPv6(p); hdrc->size() = IPv6_HEADER_SIZE; hdrc->ptype() = PT_PBU; hdrc->size() += PBU_SIZE;

iph->saddr() = proxy_coa; iph->sport() = port(); iph->daddr() = dst; iph->dport() = port();

h->H() = 1; h->A() = 1; h->P() = 1; h->type() = PBU; h->seqno() = 0;

h->lifetime() = lifetime;

h->mn_id() = mn_id; h->coa() = proxy_coa; h->haddr() = -1; h->status() = 0;

return p;}

Page 48: NS Tutorial(PMIP) (1)

LMA Operation (1/7)

•Receiving PBU/Sending PBACKLMAAgentPMIPv6Agent

process_packet()

setup_route()

process_pbu()-find_bce()

setup-route/TCL-get-pmip6-encap/TCL

send_pback()

recv()

create_pback()

send()

Page 49: NS Tutorial(PMIP) (1)

LMA Operation (2/7)

•PMIPv6Agent 의 recv 함수▫PBU 의 IP 헤더 dest port 에 따라 recv 함수

호출됨void PMIPv6Agent::recv(Packet* p, Handler *) { hdr_cmn *hdrc = HDR_CMN(p); int ptype;

ptype = hdrc->ptype(); if((ptype==PT_PBU && strcmp(node_info_, "LMA")==0) || (ptype==PT_PBACK && strcmp(node_info_, "MAG")==0)) { process_packet(p); } else { fprintf(stderr, "%s received packet with wrong type %d\n", node_info_, ptype); Packet::free(p); }}

Page 50: NS Tutorial(PMIP) (1)

LMA Operation (3/7)• process_packet 함수

▫virtual 이며 , LMAAgent 와 MAGAgent 에서 override 함

▫process_pbu 함수 호출

• process_pbu 함수▫Binding cache 찾기 , lifetime 처리▫Lifetime 에 따라 Routing 설정▫PBACK 보내기

void LMAAgent::process_packet(Packet *p) { hdr_cmn *ch = HDR_CMN(p);

if(ch->ptype() == PT_PBU) { process_pbu(p); } Packet::free(p); }

Page 51: NS Tutorial(PMIP) (1)

LMA Operation (4/7)

•process_pbu 함수 (cont’d)void LMAAgent::process_pbu(Packet *p) { hdr_ip *iph = hdr_ip::access(p); hdr_pmipv6 *h = hdr_pmipv6::access(p); int mn_id, mnaddr; BCacheEntry *bce;

mn_id = h->mn_id(); bce = find_bce(mn_id); if(!bce) { if(h->lifetime()==0) { send_pback(p, 0); return; } if((mnaddr=find_mn_prefix(mn_id))==-1) { send_pback(p, 1); return; } bce = create_bce(mn_id); bce->proxy_coa() = iph->saddr(); bce->mn_prefix() = mnaddr; bce->insert_entry(&bcache_list_); }

if(h->lifetime()==0 && bce->proxy_coa()!=iph->saddr()) { send_pback(p, 0); return; }

bce->lifetime() = h->lifetime();

if(bce->lifetime()>0) setup_route(bce); else clear_route(bce);

send_pback(bce, 0);

bce->BCacheTimer_.resched( (double)bce->lifetime());}

Page 52: NS Tutorial(PMIP) (1)

LMA Operation (5/7)• setup_route 함수 : tcl 의 setup-route 함수 호출• setup-route 함수 (TCL)

▫MN 의 주소의 패킷이 PMIPv6Encapsulator 로 전달되도록 PMIPv6Dest classifier 에 등록

Agent/PMIPv6/LMA instproc setup-route { mnaddr te } { $self instvar node_

#encap settings set clsfr_dst [$node_ set dst_classifier_] set encap [$node_ get-pmip6-encap $te]

$clsfr_dst install-by-dest $mnaddr $encap}

Page 53: NS Tutorial(PMIP) (1)

LMA Operation (6/7)• get-pmip6-encap 함수 (TCL)

▫Tunneling endpoint(te) 에 대한 PMIPv6Encapsulator 얻기

▫TE 가 존재하면 재사용 , 없으면 새로 생성Node instproc get-pmip6-encap { te } { $self instvar address_ Encaps_ if {[info exists Encaps_($te)] && $Encaps_($te) != ""} { return $Encaps_($te) }

set Encaps_($te) [new PMIPv6Encapsulator] $Encaps_($te) set addr_ [AddrParams addr2id $address_] $Encaps_($te) set port_ [Simulator set PMIPv6_TUNNEL_PORT] $Encaps_($te) set dest_addr_ $te $Encaps_($te) set dest_port_ [Simulator set PMIPv6_TUNNEL_PORT] $Encaps_($te) target [$self entry] $Encaps_($te) set node_ $self return $Encaps_($te)}

Page 54: NS Tutorial(PMIP) (1)

LMA Operation (7/7)

Page 55: NS Tutorial(PMIP) (1)

MAG Operation #2 (1/5)

•Receiving PBACKMAGAgentPMIPv6Agent

process_packet()

setup_route()

process_pback()-find_bule()

setup-route/TCL-get-pmip6-encap/TCL

recv()

clear_route()

clear-route/TCL

bule_state: BUL_S_SETUP

bule_state: BUL_S_DELETE

Page 56: NS Tutorial(PMIP) (1)

MAG Operation #2 (2/5)

•process_pback 함수▫bule 갱신 , routing 설정void MAGAgent::process_pback(Packet* p) { hdr_pmipv6 *h = hdr_pmipv6::access(p); BULEntry *bule;

bule = find_bule(h->mn_id());…… //Stop retransmit timer bule->BULTimer_.cancel(); bule->mn_prefix() = h->haddr(); bule->lifetime() = h->lifetime();

switch(bule->get_state()) { case BUL_S_SETUP: setup_route(bule); //fall through case BUL_S_REFRESH:

//Update lifetime for binding refresh bule->BULTimer_.resched( (double)bule->lifetime()*.9); if(bule->pktPBU_) { Packet::free(bule->pktPBU_); bule->pktPBU_ = 0; } bule->set_state(BUL_S_ESTABLISHED); break; case BUL_S_DELETE: clear_route(bule); bule->remove_entry(); delete bule; break; }}

Page 57: NS Tutorial(PMIP) (1)

MAG Operation #2 (3/5)• setup-route 함수 (TCL)

▫PMIPv6Decapsulator 에 MN 의 link 등록 MN 이 무선노드이면 adhoc routing protocol 을

target 으로 지정 MN 이 일반 노드이면 link 검색 후 target 지정

▫MN 의 주소의 패킷이 PMIPv6Encapsulator 로 전달되도록 PMIPv6Src classifier 에 등록

Page 58: NS Tutorial(PMIP) (1)

MAG Operation #2 (4/5)• setup-route 함수 (TCL) (cont’d)

Agent/PMIPv6/MAG instproc setup-route { mnaddr te} { $self instvar node_ set ns [Simulator instance]

set decap_ [$node_ set decap_] if {[$node_ info class] == "MobileNode/MIPBS" || [$node_ info class] =="Node/MobileNode" } { set target [$node_ set ragent_] } else { set target [[$ns link $node_ [$ns get-node-by-addr $mnaddr]] head] if {$target==""} { puts "cannot find target“ } } $decap_ install $mnaddr $target

set clsfr_src [$node_ set src_classifier_] set encap [$node_ get-pmip6-encap $te] $clsfr_src install-by-src $mnaddr $encap}

Page 59: NS Tutorial(PMIP) (1)

MAG Operation #2 (5/5)

Page 60: NS Tutorial(PMIP) (1)

Encap/Decap Operation (1/3)

•PMIPv6Src▫Classifier 가 IP 헤더의 source address 로

hash 하도록 classify 함수 변경

•PMIPv6Dest▫기존 address classifier 그대로 사용

int PMIPv6Src::classify(Packet *p) { hdr_ip* iph = hdr_ip::access(p); return mshift(iph->saddr());}

Page 61: NS Tutorial(PMIP) (1)

Encap/Decap Operation (2/3)

•PMIPv6Encapsulator 의 recv 함수▫MAG 와 LMA 의 setup-route(TCL) 함수에

의하여 MN 의 data packet 은 PMIPv6Encapsulator 의 recv 를 호출하도록 설정되어있음void

PMIPv6Encapsulator::recv(Packet* p, Handler *h) { hdr_cmn* ch = hdr_cmn::access(p); hdr_ip* hdr = hdr_ip::access(p); hdr_ip6encap *enh = HDR_IP6ENCAP(p);

if (--hdr->ttl_ <= 0) { Packet::free(p); return; } enh->hdr_ = *hdr; enh->ptype_ = ch->ptype();

hdr->saddr() = here_.addr_; hdr->sport() = here_.port_; hdr->daddr() = dest_.addr_; hdr->dport() = dest_.port_; hdr->ttl() = defttl_;

ch->size() += IPv6_HEADER_SIZE; target_->recv(p,h);}

Page 62: NS Tutorial(PMIP) (1)

Encap/Decap Operation (3/3)• PMIPv6Decapsulator 의 recv 함수

▫ 외부 헤더와 내부 헤더를 교환void PMIPv6Decapsulator::recv(Packet* p, Handler *h) { hdr_cmn* ch = hdr_cmn::access(p); hdr_ip *hdr = hdr_ip::access(p); hdr_ip6encap *enh = HDR_IP6ENCAP(p); hdr_ip tmph;

tmph = *hdr; *hdr = enh->hdr_; enh->hdr_ = tmph;

NsObject* link = find(p); if (link == NULL || hdr->ttl_ <= 0) { printf("Link not found\n"); Packet::free(p); return; }

ch->size() -= IPv6_HEADER_SIZE; link->recv(p,h);}