+ All Categories
Home > Documents > 期中 NS-2 Project

期中 NS-2 Project

Date post: 23-Jan-2016
Category:
Upload: sorley
View: 38 times
Download: 0 times
Share this document with a friend
Description:
期中 NS-2 Project. Use NS2 to implement TS and UIR (Updated Invalidation Report) schemes Part 1: TS scheme: (60%) - PowerPoint PPT Presentation
Popular Tags:
30
1 期期 NS-2 Project Use NS2 to implement TS and UIR (Updated Invalidation Report) schemes Part 1: TS scheme: (60%) D. Barbara and T. Imielinski, “Sleepers and Workaholics: Caching Strategies in Mobile Environments ,” Proc. ACM SIGMOD Int’l Conf. on Management of Data, Vol. 23, no. 2, pp. 1-12, May 1994. Part 2: UIR scheme (40%) G. Cao, “A Scalable Low-Latency Cache Invalidation Strategy for Mobile Environments ,” IEEE Trans. on Knowledge and Data Engineering, Vol. 15, No. 5, pp. 1251-1265, Sept./Oct. 2003.
Transcript
Page 1: 期中  NS-2 Project

1

期中 NS-2 Project Use NS2 to implement TS and UIR (Updated Invalidation Report) schemes

Part 1: TS scheme: (60%) D. Barbara and T. Imielinski, “Sleepers and Workaholics: Caching

Strategies in Mobile Environments,” Proc. ACM SIGMOD Int’l Conf. on Management of Data, Vol. 23, no. 2, pp. 1-12, May 1994.

Part 2: UIR scheme (40%) G. Cao, “A Scalable Low-Latency Cache Invalidation Strategy for Mobile

Environments,” IEEE Trans. on Knowledge and Data Engineering, Vol. 15, No. 5, pp. 1251-1265, Sept./Oct. 2003.

Page 2: 期中  NS-2 Project

2

BS

Concept of Cache Invalidation Report scheme- BS use broadcast to invalidate MHs’ cache

MH

Page 3: 期中  NS-2 Project

3

The advantage of IR

Broadcast Scalable

Property of wireless networks MHs wake up and sleep for saving energy Disconnection issue

Page 4: 期中  NS-2 Project

4

Cache Invalidation Report (IR), TS (Timestamp) scheme

D. Barbara and T. Imielinski, “Sleepers and Workaholics: Caching Strategies in Mobile Environments,” Proc. ACM SIGMOD Int’l Conf. on Management of Data, Vol. 23, no. 2, pp. 1-12, May 1994.

Page 5: 期中  NS-2 Project

5

Invalidation Report (IR) structure

Time

w=i*L

t1t2 t3

t4 t5 t6t7 t8

t9

Broadcastwindow

L

Page 6: 期中  NS-2 Project

6

MHs receive IR from BS (1/2)

Page 7: 期中  NS-2 Project

7

MHs receive IR from BS (2/2)

Page 8: 期中  NS-2 Project

8

Page 9: 期中  NS-2 Project

9

class aodv – database

struct database { int data_id; float data_size; float nearest_update_time; int flag; // 用來模擬資料的狀態,例如存在與否 }; database server_db[1000];

aodv.h

Page 10: 期中  NS-2 Project

10

class aodv – MHs’ cache

#define max_cache_entry 100

struct MH_cache_entry_struct { int data_id; float cached_time; }; MH_cache_entry_struct MH_cache[max_cache_entry];

aodv.h

Page 11: 期中  NS-2 Project

11

class aodv - TS scheme For Base station (server)

/*1.*/ void BS_Database_Update_Model(); /*2.*/ void BS_Broadcast_IR_to_MHs(); /*3.*/ void BS_Recv_data_request_from_MH(Packet *p);

For Mobile host (MHs) /*4.*/ void MHs_Query_Model(); /*5.*/ int MH_Lookup_Local_Cache(int requested_data_id); /*6.*/ void MH_send_data_request_to_BS(int requested_data_id);

/*7.*/ void MHs_Recv_IR_from_BS(Packet *p); /*8.*/ void MH_cache_placement(int data_id); /*9.*/ int MH_cache_replacement_LRU();

aodv.h

Page 12: 期中  NS-2 Project

1212

/*1.*/ void BS_Database_Update_Model( );

void AODV::BS_Database_Update_Model() { if (CURRENT_TIME > DATABASE_NEXT_UPDATE) { int update_data_id = rand()%(TOTAL_DATA_SET-1)+1; server_db[update_data_id].nearest_update_time = CURRENT_TIME; DATABASE_NEXT_UPDATE = (rand()%(DATABASE_UPDATE_MEAN*2)+1); } }

aodv.cc

註 : 必須寫 1 個 timer 來觸發這個 function ,而且只有被模擬成 BS 的節點,會執 行到這個 timer (function) 。

Page 13: 期中  NS-2 Project

13

void AODV::BS_Broadcast_IR_to_MHs(void) { if (CURRENT_TIME >= NEXT_IR_TIME) { Packet *IR_packet = Packet::alloc(); struct hdr_cmn *ch = HDR_CMN(IR_packet); struct hdr_ip *ih = HDR_IP(IR_packet); struct hdr_aodv_reply *header = HDR_AODV_REPLY(IR_packet);

header->rp_type = AODVTYPE_HELLO; header->Message_type = 1;

/*2.*/ void BS_Broadcast_IR_to_MHs();

aodv.cc

Page 14: 期中  NS-2 Project

14

int IR_size = 0; float IR_w_interval_time = CURRENT_TIME - (W_WINDOW * IR_INTERVAL);

for(int a=1;a<TOTAL_DATA_SET;a++) { header->Content[a].data_reply_flag = 0; header->Content[a].update_time = 0; if ((BS_database[a].nearest_update_time>IR_w_interval_time)&& (BS_database[a].nearest_update_time>0)) { header->Content[a].update_time = BS_database[a].nearest_update_time; IR_size += 4*2; } header->Content[a].data_reply_flag = scheduled_data[a]; scheduled_data[a] = 0; }

Page 15: 期中  NS-2 Project

15

printf("\nIR_size=%d bytes",IR_size); ch->size() = IP_HDR_LEN + IR_size; ch->ptype() = PT_AODV; ch->iface() = -2; ch->error() = 0; ch->addr_type() = NS_AF_NONE; ch->prev_hop_ = index;

ih->saddr() = index; ih->daddr() = IP_BROADCAST; ih->sport() = RT_PORT; ih->dport() = RT_PORT; ih->ttl_ = 1; Scheduler::instance().schedule(target_, IR_packet, 0.01* Random::uniform()); } }

Page 16: 期中  NS-2 Project

16

struct hdr_aodv_reply { u_int8_t rp_type; // Packet Type u_int8_t reserved[2]; u_int8_t rp_hop_count; // Hop Count nsaddr_t rp_dst; // Destination IP Address u_int32_t rp_dst_seqno; // Destination Sequence Number nsaddr_t rp_src; // Source IP Address double rp_lifetime; // Lifetime double rp_timestamp; // when corresponding REQ sent; int Message_type; // 1:MHs_Recv_IR_from_BS // 2:BS_Recv_data_request_from_MH int Requested_data_id; IR_struct Content[1001]; };

aodv_packet.hstruct IR_struct{ float update_time; int data_reply_flag;};

Page 17: 期中  NS-2 Project

17

/*3.*/ void BS_Recv_data_request_from_MH(Packet *p);

aodv.cc

void AODV::BS_Recv_data_request_from_MH(Packet *data_request_packet){ struct hdr_aodv_reply *header = HDR_AODV_REPLY(data_request_packet); struct hdr_cmn *ch = HDR_CMN(data_request_packet); int requested_data_id = header->Requested_data_id; scheduled_data[requested_data_id] = 1; Packet::free(data_request_packet);}

Page 18: 期中  NS-2 Project

18

/*4.*/ void MHs_Query_Model();aodv.ccvoid AODV::MHs_Query_Model(){ if ((MH_status==0)&&(CURRENT_TIME > NEXT_QUERY_TIME)) { int query_pro = rand() % 250 + 1; //decide the probability of query event { if (query_pro<=15) { queried_data_id = Query_Data_ID(); //based on the access prob. of hot/cold data query_time = CURRENT_TIME; int result = MH_Lookup_Local_Cache(queried_data_id ); if (result==1) //local cache hit MH_status = 1; if (result==0) //local cache miss { MH_status = 2; MH_send_data_request_to_BS(queried_data_id );

} NEXT_QUERY_TIME += (rand()%(MEAN_QUERY_ARRIVAL*2))+1; } } }}

Page 19: 期中  NS-2 Project

19

aodv.cc

int AODV::MH_Lookup_Local_Cache(int data_id){ for(int a=0;a<max_cache_entry;a++) { if (MH_cache[a].data_id==data_id) { return 1; } } return 0;}

/*5.*/ int MH_Lookup_Local_Cache(int requested_data_id);

Page 20: 期中  NS-2 Project

20

aodv.ccvoid AODV::MH_send_data_request_to_BS(int requested_data_id){ printf(",send data request to BS",index,CURRENT_TIME);

Packet *data_request_packet = Packet::alloc(); struct hdr_cmn *ch = HDR_CMN(data_request_packet); struct hdr_ip *ih = HDR_IP(data_request_packet); struct hdr_aodv_reply *header = HDR_AODV_REPLY(data_request_packet); header->rp_type = AODVTYPE_HELLO;

header->Message_type = 2; header->Requested_data_id = requested_data_id;

ch->size() = IP_HDR_LEN + 4; //data id:4 bytes ch->ptype() = PT_AODV; ch->iface() = -2; ch->error() = 0; ch->addr_type() = NS_AF_NONE; ch->prev_hop_ = index;

ih->saddr() = index; ih->daddr() = 1; //Base station ih->sport() = RT_PORT; ih->dport() = RT_PORT; ih->ttl_ = 1;

Scheduler::instance().schedule(target_, data_request_packet, 0.01* Random::uniform());}

/*6.*/ void MH_send_data_request_to_BS(int requested_data_id);

Page 21: 期中  NS-2 Project

21

aodv.cc

void AODV::MHs_Recv_IR_from_BS(Packet *IR_packet){ struct hdr_aodv_reply *header = HDR_AODV_REPLY(IR_packet);

// 第 1 件事情 : Use IR to remove the invalid cached data in MH’s cache for(int a=0;a<max_cache_entry;a++) { int data_id = MH_cache[a].data_id; if (MH_cache[a].cached_time < header->Content[data_id].update_time) { MH_cache[a].data_id = 0; MH_cache[a].cached_time = 0; } }

/*7.*/ void MHs_Recv_IR_from_BS(Packet *p);

Page 22: 期中  NS-2 Project

22

// 第 2 件事情if (MH_status == 3) //Cache hit, IR invalid, and then receive data reply { MH_cache_placement(queried_data_id); MH_status = 0; queried_data_id = 0; query_time = 0; }

MH_status = 3MH_status = 1

latency

Cache hit IR invalid data reply

IR IR IR

Page 23: 期中  NS-2 Project

23

// 第 3 件事情if (MH_status == 1) //Cache hit, waiting IR { if (MH_cache[queried_data_id].cached_time >= header-> Content[queried_data_id].update_time) { MH_status = 0; queried_data_id = 0; query_time = 0; }

if (MH_cache[queried_data_id].cached_time < header->Content[queried_data_id].update_time) { MH_status = 3; Remove_invalid_cached_data(queried_data_id); MH_send_data_request_to_BS(queried_data_id); } }

MH_status = 1

Cache hit

IR IR IR

latency

Page 24: 期中  NS-2 Project

24

// 第 4 件事情 if (MH_status == 2) //Cache miss, wait and receive data reply { MH_cache_placement(queried_data_id,data_Q_bit,data_U_bit); MH_status = 0; queried_data_id = 0; query_time = 0; } Packet::free(IR_packet); }

MH_status = 2

latency

Cache miss data reply

IR IR IR

Page 25: 期中  NS-2 Project

25

/*8.*/ void MH_cache_placement(int data_id);

aodv.cc

void AODV::MH_cache_placement(int data_id){ int place_location = 0; place_location = MH_cache_replacement_LRU(); MH_cache[place_location].data_id = data_id; MH_cache[place_location].cached_time = CURRENT_TIME;}

Page 26: 期中  NS-2 Project

26

/*9.*/ int MH_cache_replacement_LRU();

aodv.cc

int AODV::MH_cache_replacement_LRU() { int compared_time = 99999; int replace_location = 0;

for(int a=0;a<max_cache_entry;a++) { if (MH_cache[a].cached_time < compared_time) { compared_time = MH_cache[a].cached_time; replace_location = a; } } return replace_location; }

Page 27: 期中  NS-2 Project

27

期中 NS-2 Project – Part 1 Implement TS scheme and obtain the following results: (60%)

(5%) 1. Number of database update:___________(5%) 2. Number of total query count: ___________(5%) 3. Number of total hit count: ___________(5%) 4. Number of total miss count: ___________(5%) 5. Number of total hit and valid by IR: __________(5%) 6. Number of total hit and invalid by IR: _________(5%) 7. Number of uplink request:_________(5%) 8. Ratio of uplink per query:__________(5%) 9. Average latency for local hit and valid by IR: __________(5%) 10. Average latency for local hit and invalid by IR: ___________(5%) 11. Average latency for local miss: _________(5%) 12. Average latency for above three:___________

Page 28: 期中  NS-2 Project

2828

Simulation time: 3000 seconds

Page 29: 期中  NS-2 Project

29

期中 NS-2 Project – Part 2 Implement UIR scheme and than obtain the results the same as the paper: (40%)

29

Simulation time: 3000 seconds

Page 30: 期中  NS-2 Project

30

Updated Invalidation Report (UIR) scheme

G. Cao, “A Scalable Low-Latency Cache Invalidation Strategy for Mobile Environments,” IEEE Trans. on Knowledge and Data Engineering, Vol. 15, No. 5, pp. 1251-1265, Sept./Oct. 2003.


Recommended