300 likes | 399 Views
期中 NS-2 Project. Use NS2 to implement TS and UIR (Updated Invalidation Report) schemes Part 1: TS scheme: (60%)
E N D
期中 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.
Concept of Cache Invalidation Report scheme - BS use broadcast to invalidate MHs’ cache MH BS
The advantage of IR • Broadcast • Scalable • Property of wireless networks • MHs wake up and sleep for saving energy • Disconnection issue
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.
Invalidation Report (IR) structure t9 t2 t7 t4 t5 t6 t8 t1 t3 Time L Broadcast window w=i*L
aodv.h class aodv – database • struct database • { • int data_id; • float data_size; • float nearest_update_time; • int flag; //用來模擬資料的狀態,例如存在與否 • }; • database server_db[1000];
aodv.h 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 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.cc /*1.*/ void BS_Database_Update_Model( ); 註: 必須寫1個timer來觸發這個function,而且只有被模擬成BS的節點,會執 行到這個timer (function)。 • 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); • } • } 12
aodv.cc /*2.*/ void BS_Broadcast_IR_to_MHs(); • 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;
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; • }
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()); • } • }
aodv_packet.h struct IR_struct { float update_time; int data_reply_flag; }; • 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.cc /*3.*/ void BS_Recv_data_request_from_MH(Packet *p); 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); }
aodv.cc /*4.*/ void MHs_Query_Model(); void 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; } } } }
aodv.cc /*5.*/ int MH_Lookup_Local_Cache(int requested_data_id); 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; }
aodv.cc /*6.*/ void MH_send_data_request_to_BS(int requested_data_id); void 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()); }
aodv.cc /*7.*/ void MHs_Recv_IR_from_BS(Packet *p); 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; } }
//第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; } IR IR IR Cache hit data reply IR invalid MH_status = 1 MH_status = 3 latency
//第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); } } IR IR IR Cache hit MH_status = 1 latency
//第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); • } IR IR IR Cache miss data reply MH_status = 2 latency
aodv.cc /*8.*/ void MH_cache_placement(int data_id); 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; }
aodv.cc /*9.*/ int MH_cache_replacement_LRU(); • 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; • }
期中 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:___________
期中 NS-2 Project – Part 2 • Implement UIR scheme and than obtain the results the same as the paper: (40%) Simulation time: 3000 seconds 29
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.