The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
University
| Teaching Since: | Apr 2017 |
| Last Sign in: | 438 Weeks Ago, 2 Days Ago |
| Questions Answered: | 9562 |
| Tutorials Posted: | 9559 |
bachelor in business administration
Polytechnic State University Sanluis
Jan-2006 - Nov-2010
CPA
Polytechnic State University
Jan-2012 - Nov-2016
Professor
Harvard Square Academy (HS2)
Mar-2012 - Present
 am looking to have c++ or c program on windows work as schedular of Round Robin type which could implement Weighted Fair Queueing, i sent sample program so simelar one with simple report or notes expalining the structure of your program.m regards hatim
The PC Switch
Â
Scheduler
Â
*/
Â
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h> // socket() & bind()
#include <errno.h> // for DieWithError() function
#include <arpa/inet.h> // sockaddr_in
Â
// Defining all the input and output ports of the scheduler
#define INPUT_PORT 50002
#define OUTPUT_PORT 50003
#define LOCAL_ADDRESS "127.0.0.1"
#define MAX_MSG_LEN 200
Â
typedef struct packet packet; // Struct of packet being sent between each module
struct packet {
char ip_dest[4][9];
char ip_source[4][9];
short int dataLength;
char data[100];
int frameCheck;
int fromPort;
int toPort;
int sequenceNum;
int portSequenceNum;
int timer;
};
Â
typedef struct packetBuffer packetBuffer;
// Declare buffer struct that holds packet struct
struct packetBuffer {
packet queuedPacket;
packetBuffer *nextSource;
packetBuffer *nextSameSource;
};
Â
// Misc functions
void DieWithError(char *errorMessage);
int bin2dec(char *binary);
Â
int main(void) {
struct sockaddr_in fabOUT_addr;// client info (fabric) variable, data given when received message
struct sockaddr_in schedIN_addr;// struct for incoming packets
struct sockaddr_in schedOUT_addr;// struct for outgoing packets
unsigned int fabAddrLen;// int to store length of client address (fabric) data when received
packet recvPacket, outGoing;// packet struct that will be received
int sockIN, sockOUT, recvMsgLen, n, ip[4], i=0, port, pIP[4], qIP[4], dropped=0, time=0, lastTime=0, timeToSend=4, maxSameSource=4;
packetBuffer *current = NULL;// keep track of where loop is pointing to in queue row
packetBuffer *newPacket = NULL;// used when creating new queue element
  packetBuffer *temp = NULL; // temp packetBuffer element when deleting root of queue row
  packetBuffer *previous[8]; // keep track of previous element in queue
packetBuffer *nextSend[8];// pointer to next element to be sent on port n
packetBuffer *root[8];// array of queues, queue 0 is for gateway port, 1-7 corresponding to other ports
Â
//----------------Network code----------------
// Open socket
if((sockIN = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
DieWithError("socket() failed");
if((sockOUT = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
DieWithError("socket() failed");
Â
// Construct local address structure
bzero((char *)&schedIN_addr, sizeof(schedIN_addr));// zeroes out struct before data copied
  schedIN_addr.sin_family = AF_INET; // specifies Address Family
  schedIN_addr.sin_addr.s_addr = htonl(INADDR_ANY); // accept from any network interface
  schedIN_addr.sin_port = htons(INPUT_PORT); // Using port 50002
  // Construct outgoing address structure
bzero((char *)&schedOUT_addr,sizeof(schedOUT_addr));// zeroes out struct before data copied
  schedOUT_addr.sin_family = AF_INET; // specifies Address Family
  schedOUT_addr.sin_addr.s_addr = inet_addr(LOCAL_ADDRESS); // Connect to local address
  schedOUT_addr.sin_port = htons(OUTPUT_PORT); // output port 50003
   Â
int----------- ma-----------in(-----------) {----------- in-----------t c-----------oun-----------t,j-----------,n,-----------tim-----------e,r-----------ema-----------in,-----------fla-----------g=0-----------,ti-----------me_-----------qua-----------ntu-----------m; -----------int----------- wa-----------it_-----------tim-----------e=0-----------,tu-----------rna-----------rou-----------nd_-----------tim-----------e=0-----------,at-----------[10-----------],b-----------t[1-----------0],-----------rt[-----------10]-----------; p-----------rin-----------tf(-----------"En-----------ter----------- To-----------tal----------- Pr-----------oce-----------ss:-----------\t -----------");-----------