// redefinition for generic network unsigned int tdma_bus::allocate_BW(phy_address src, unsigned int required_bps) { std::string rpt_msg; unsigned required_slots; #ifdef _REPORT_TDMA_BUS_CONFIGURATION rpt_msg= "Requesting "; rpt_msg+= std::to_string(required_bps); rpt_msg+= " (bps) to sender physical address (PE) "; rpt_msg+= src->name(); SC_REPORT_INFO("KisTA: TDMA bus",rpt_msg.c_str()); #endif // calculated required slots required_slots = (unsigned int)((double)required_bps/(double)channel_eBW)+1; allocate_channels(src,required_slots); #ifdef _REPORT_TDMA_BUS_CONFIGURATION rpt_msg= "Allocating "; rpt_msg+= std::to_string(required_slots*channel_eBW); rpt_msg+= " (bps) to sender physical address (PE) "; rpt_msg+= src->name(); SC_REPORT_INFO("KisTA: TDMA bus",rpt_msg.c_str()); #endif return required_slots*channel_eBW; }
inline static union Channel *request_channel(uint8_t proto, uint16_t port) { debug("channel: request %d %d", proto, port); if(!context.free_channels) allocate_channels(); if(!context.free_channels) return NULL; assert(context.free_channels); union Channel *channel = context.free_channels; context.free_channels = (union Channel *) context.free_channels->base.next; if(context.free_channels) context.free_channels->base.prev = NULL; memset(channel, 0, sizeof(union Channel)); channel->base.next = &context.channels->base; if(context.channels) context.channels->base.prev = &channel->base; context.channels = channel; channel->base.proto = proto; authentication_prepare_challenge(&channel->base.token); struct MessageOpenChannel ope; ope.type = OPEN_CHANNEL; memcpy(&ope.challenge, &channel->base.token, CHALLENGE_LENGTH); ope.port = htons(port); ope.proto = proto; bufferevent_write( context.control_buffers, &ope, sizeof(ope)); authentication_prepare_response(&channel->base.token, &channel->base.token, options.password); channel->base.alive = 2; return channel; }