int flowScheduler_schedule_flow(struct in6_addr ip6_origin,struct in6_addr ip6_destination,
    uint32_t transport_protocol, uint16_t transport_source_port,
    uint16_t transport_destination_port,
    uint8_t traffic_class, uint32_t flow_label){

    fmpmip_flow_cache_entry *fce;
    struct mn_nai_association mn_nai_ip;
    memset(&mn_nai_ip, 0, sizeof(struct mn_nai_association));
    uint32_t  mark=0;

    mn_nai_ip.ip6 = ip6_destination;

    pmip_cache_iterate(find_NAI, &mn_nai_ip);

    fce = flowmob_cache_get(&ip6_origin,&ip6_destination,
        transport_protocol,transport_source_port,
        transport_destination_port,traffic_class,
        flow_label);

    if(fce != NULL){
        dbg("This flow is already in the flow cache table with the mark %d\n",fce->mark);
        flowmob_cache_release_entry(fce);
        return mark;
    }

    mark = get_flow_fwmark(mn_nai_ip.client_nai) ;
    if(mark>0){
       fmpmip_flow_cache_entry * flowMob= flowmob_cache_alloc();
       memcpy(&flowMob->ip6_origin , &ip6_origin, sizeof(struct in6_addr));
       memcpy(&flowMob->ip6_destination , &ip6_destination, sizeof(struct in6_addr));
       flowMob->transport_protocol = transport_protocol;
       flowMob->transport_source_port = transport_source_port;
       flowMob->transport_destination_port = transport_destination_port;
       flowMob->traffic_class = traffic_class;
       flowMob->flow_label = flow_label;
       flowMob->mark=mark;
       flowMob->client_nai=mn_nai_ip.client_nai;
       flowMob->BID=mn_nai_ip.BID;
       flowmob_cache_add(flowMob);
       dbg("This is a new flow. A new entry in the flow cache table was created \n");
   }else{
       dbg("Can't match this flow woth any of the connected clients\n");
       dbg("This flow will continue withouth intervention.\n");
   }

   return mark;
}
//---------------------------------------------------------------------------------------------------------------------
void pmip_cleanup(void)
//---------------------------------------------------------------------------------------------------------------------
{
	// Anh Khuong: add
    if (is_lma()) {
#ifdef LMA_BUFFERING
    	pmip_buffering_cleanup();
#endif
#ifdef USE_PMIP_RO
    	if (!undefined_RO)
    		pmip_ro_cleanup();
#endif
    }
    if (is_mag()) {
#ifdef NAMYEONG_PAPER
		pmip_buffering_cleanup();
#endif
    }

    // Anh Khuong: end
	//Release the pmip cache ==> deletes the routes and rules and "default route on PMIP" and tunnels created.
    dbg("Release all occupied resources...\n");
    //delete the default rule.
    dbg("Remove default rule...\n");
    rule_del(NULL, RT6_TABLE_MIP6, IP6_RULE_PRIO_MIP6_FWD, RTN_UNICAST, &in6addr_any, 0, &in6addr_any, 0, 0);

    dbg("Release pmip_cache...\n");
    pmip_cache_iterate(pmip_cache_delete_each, NULL);

//#undef HAVE_PCAP_BREAKLOOP
#define HAVE_PCAP_BREAKLOOP
#ifdef HAVE_PCAP_BREAKLOOP
    /*
    * We have "pcap_breakloop()"; use it, so that we do as little
    * as possible in the signal handler (it's probably not safe
    * to do anything with standard I/O streams in a signal handler -
    * the ANSI C standard doesn't say it is).
    */
    if (is_mag()) {
        pcap_breakloop(pcap_descr);
   }
#endif
}