int FIFONode::send(Packet* packet) { Address nhop; PacketQueue* queue; QueueMapIterator qiter; // Compute the nexthop nhop = topology->nexthop(address(), packet->destination); // Find the queue qiter = queue_map.find(nhop); if (qiter == queue_map.end()) { // An entry doesn't exist queue = new PacketQueue(max_queue_size, address(), nhop); QueueMapPair np(nhop, queue); queue_map.insert(np); } else { queue = (*qiter).second; } // Check if there is space if (queue->enq(packet)) { TRACE(TRL2, "Enqueued at %d packet (src %d, dst %d, id %d)\n", address(), packet->source, packet->destination, packet->id); send_it(nhop); return 1; } TRACE(TRL2, "Queue full at %d, dropped packet (src %d, dst %d, id %d)\n", address(), packet->source, packet->destination, packet->id); delete packet; return 0; }
static unsigned int remnode_send(remnode_item *remnode, pwr_sClass_RemTrans *remtrans, char *buf, int buffer_size) { unsigned int sts; sts = send_it(buf, buffer_size); return sts; }
void send_pollbuff(remnode_item *remnode, pssupd_buffer_vnet *buf) { unsigned int sts, buf_size; /* Fill in remaining data in poll telegram */ RemUtils_AsciiToR50("PSSUPD", (short *) &buf->receive_task); buf->common_name[0] = poll_id[0]; buf->common_name[1] = poll_id[1]; buf_size = buf->length * 2; /* Convert to bytes */ sts = send_it((char*)buf, buf_size); return; }
int main (int argc, char *argv[]) { if (argc > 1) { if (!strcasecmp ("create", argv[1])) create_it (); if (!strcasecmp ("remove", argv[1])) remove_it (); if (!strcasecmp ("receive", argv[1])) receive_it (); if (!strcasecmp ("send", argv[1])) send_it (); } printf ("Usage: %s create | remove | receive | send \n", argv[0]); exit (-1); }
void FIFONode::send_done(Address nhop) { PacketQueue* queue; QueueMapIterator qiter; qiter = queue_map.find(nhop); ASSERT(qiter != queue_map.end()); queue = (*qiter).second; TRACE(TRL2, "Ongoing transmission at %d to nexthop %d completed\n", address(), nhop); queue->pending_send = 0; send_it(nhop); return; }
void FIFONode::receive(Packet* pkt) { PacketQueue* queue; QueueMapIterator qiter; Address nhop; // If the packet is for us, drop it if (pkt->destination == address()) { delete pkt; return; } // Otherwise, forward packet onwards nhop = topology->nexthop(address(), pkt->destination); // Find the queue qiter = queue_map.find(nhop); if (qiter == queue_map.end()) { // An entry doesn't exist queue = new PacketQueue(max_queue_size, address(), nhop); QueueMapPair np(nhop, queue); queue_map.insert(np); } else { queue = (*qiter).second; } // Check if there is space if (queue->enq(pkt)) { TRACE(TRL2, "Forwarding at %d nexthop %d packet (src %d, dst %d, id %d)\n", address(), nhop, pkt->source, pkt->destination, pkt->id); send_it(nhop); return; } TRACE(TRL2, "Queue full at %d, dropped packet (src %d, dst %d, id %d)\n", address(), pkt->source, pkt->destination, pkt->id); delete pkt; return; }
/* * This is the kthread function. Although I didn't used it you can always pass it values through the data variable. */ static int main_loop(void* data) { sample_t *samples; packet_t * pkt; uint32_t len, i = 0; static uint32_t seq = 0; if (sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &udp_socket) < 0) { printk(KERN_EMERG "Unable to create socket.\n"); return 0; } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_addr.s_addr = in_aton(bind_ip); my_addr.sin_port = htons(sport); if(udp_socket->ops->bind(udp_socket, (struct sockaddr*) &my_addr, sizeof(struct sockaddr)) < 0) { printk(KERN_EMERG "Unable to bind socket to %s:%d.\n", bind_ip, sport); return 0; } /* * If you need debug, just compile the code with -D__DEBUG__ */ #ifdef __DEBUG__ printk(KERN_INFO "Bound to %s:%u\n", bind_ip, sport); #endif while (1) { if (kthread_should_stop()) { #ifdef __DEBUG__ printk(KERN_INFO "Stopping sender thread...\n"); #endif break; } len = read_nsamples(&samples); if(len > 0) { #ifdef __DEBUG__ printk(KERN_INFO "Read %d samples:\n", len); #endif for(i = 0; i < len; i += 1) { pkt = prepare_packet(&(samples[i]), seq++, node_id); if(pkt == NULL) { printk(KERN_EMERG "Was not able to prepare the packet to send\n"); continue; } send_it(pkt); kfree(pkt); } kfree(samples); // Never forget samples was allocated in read_nsamples and so has to be freed } // schedule(); //This is similar to kill a fly with a bazooka, but it works. msleep(SLEEP_TIME_MS); } return 0; }