Commit 17d02668 authored by Abhijeet Joglekar's avatar Abhijeet Joglekar

First version of the delay node agent. Tested for a series of UP/DOWN/MODIFY

events .
parent 440c75d0
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = event/delay-agent
include $(OBJDIR)/Makeconf
all: delay-agent
include $(TESTBED_SRCDIR)/GNUmakerules
CFLAGS += -pthread
#CFLAGS += -DDEBUG
CFLAGS += -O -g -Wall
CFLAGS += -I. -I${OBJDIR} -I$(SRCDIR)/../lib -I$(TESTBED_SRCDIR)/lib/libtb
CFLAGS += `elvin-config --cflags vin4mt`
LDFLAGS += -pthread -static
LDFLAGS += -L../lib -L${OBJDIR}/lib/libtb
LIBS += -levent -ltb -lcipher
#
# XXX elvin-config adds -lc which is rather bogus, and messes up -pthread
# build on freebsd. I made a vain attempt to filter it out, but
# gave up quickly. Deal with it later.
#
#LIBS += `elvin-config --libs vin4mt`
LIBS += -L/usr/local/lib -lvin4mt -lvin4c -lvin4 -lssl -lcrypto -lm
OBJS = main.o callback.o
delay-agent: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
$(OBJS): main.h ../lib/libevent.a
#install: $(addprefix $(INSTALL_SBINDIR)/, event-sched)
clean:
/bin/rm -f *.o delay-agent
/*
* agent-callback-dummy.c --
*
* Delay node agent callback handling.
*
*
* @COPYRIGHT@
*/
/******************************* INCLUDES **************************/
#include "main-d.h"
/******************************* INCLUDES **************************/
/******************************* EXTERNS **************************/
extern structlink_map link_map[MAX_LINKS];
extern int link_index;
extern int s_dummy;
/******************************* EXTERNS **************************/
/********************************FUNCTION DEFS *******************/
/*************************** agent_callback **********************
This function is called from the event system when an event
notification is recd. from the server. It checks whether the
notification is valid (sanity check). If not print a warning,else
call handle_pipes which does the rest of thejob
*************************** agent_callback **********************/
void agent_callback(event_handle_t handle,
event_notification_t notification, void *data)
{
#define MAX_LEN 50
char objname[MAX_LEN];
char eventtype[MAX_LEN];
int l_index = -1;
#ifdef DEBUG
info ("entering callback \n");
#endif
/* get the name of the object, eg. link0 or link1*/
if(event_notification_get_string(handle,
notification,
"OBJNAME", objname, MAX_LEN) == 0){
error("could not get the objname \n");
return;
}
/* check we are handling the objectname for which we have recd an event */
if ((l_index = check_object(objname)) == -1){
error("not handling events for this object\n");
return;
}
/* get the eventtype, eg up/down/modify*/
if(event_notification_get_string(handle,
notification,
"EVENTTYPE", eventtype, MAX_LEN) == 0){
error("could not get the eventtype \n");
return;
}
/* call function to handle this event for this object */
handle_event(objname, eventtype, notification,handle);
#ifdef DEBUG
info ("exiting callback \n");
#endif
return;
}
/******************** handle_pipes ***************************************
******************** handle_pipes ***************************************/
void handle_event (char *objname, char *eventtype,
event_notification_t notification, event_handle_t handle)
{
#ifdef DEBUG
info ("entering handle_event \n");
#endif
if(strcmp(eventtype, TBDB_EVENTTYPE_UP) == 0){
handle_link_up(objname);
}
else if(strcmp(eventtype, TBDB_EVENTTYPE_DOWN) == 0){
handle_link_down(objname);
}
else if(strcmp(eventtype, TBDB_EVENTTYPE_MODIFY) == 0){
handle_link_modify(objname, handle, notification);
}
else error("unknown link event type\n");
#ifdef DEBUG
info ("exiting handle_event \n");
#endif
}
void handle_link_up(char * linkname){
#ifdef DEBUG
info ("entering handle_link_up \n");
#endif
info("recd. UP event for link = %s\n", linkname);
#ifdef DEBUG
info ("exiting handle_link_up \n");
#endif
}
void handle_link_down(char * linkname)
{
#ifdef DEBUG
info ("entering handle_link_down \n");
#endif
info("recd. DOWN event for link = %s\n", linkname);
#ifdef DEBUG
info ("exiting handle_link_down \n");
#endif
}
void handle_link_modify(char *linkname, event_handle_t handle,
event_notification_t notification)
{
char argvalue[50];
char * argtype;
int bw = 0, delay = 0;
#ifdef DEBUG
info ("entering handle_link_modify \n");
#endif
info("recd. MODIFY event for link = %s\n", linkname);
if(event_notification_get_string(handle,
notification,
"ARGS", argvalue, 50) != 0){
argtype = strtok(argvalue,"=");
if(strcmp(argtype,"BANDWIDTH")== 0){
bw = atoi(strtok(NULL," "));
info("Bandwidth = %d \n", bw);
}else if (strcmp(argtype,"DELAY")== 0){
delay = atoi(strtok(NULL," "));
info("Delay = %d \n", delay);
}else error("unrecognized argument\n");
}
#ifdef DEBUG
info ("exiting handle_link_modify \n");
#endif
}
int check_object (char *objname)
{
return search(objname);
}
/*********************** search ********************************
This function does a linear search on the link_map and returns
the index of the link_map entry which matches with the objectname
from the event notification
There will hardly be a few entries in this table, so we dont need
anything fancier than a linear search.
*********************** search ********************************/
int search(char* objname){
/* for now we do a linear search, maybe bin search later*/
int i;
for(i = 0; i < link_index; i++){
if(strcmp(link_map[i].linkname, objname) == 0)
return i;
}
return -1;
}
This diff is collapsed.
/* AGENT-MAIN-DUMMY.H*/
#ifndef _AGENT_MAIN_DUMMY_H_
#define _AGENT_MAIN_DUMMY_H_
#if 0
#include <ctype.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include "event.h"
#include <stdio.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "event.h"
#include "tbdefs.h"
#include "log.h"
#if 0
#include "tbdb.h"
#endif
#if 0
/* these are defined in testbed/lib/libtb/tbdb.h, will include
that directory later and then throw out these defines
*/
#define TBDB_OBJECTTYPE_LINK "LINK"
#define TBDB_EVENTTYPE_UP "UP"
#define TBDB_EVENTTYPE_DOWN "DOWN"
#define TBDB_EVENTTYPE_MODIFY "MODIFY"
#endif
/*************************INCLUDES******************************************/
/**************************DEFINES******************************************/
#define MAX_LINE_LENGTH 256
#define MAX_LINKS 4 /* 4 simplex or 2 duplex, since we have 4 interfaces
on delay nodes*/
/**************************DEFINES******************************************/
/*************************USER DEFINED TYPES********************************/
#define PIPE_QSIZE_IN_BYTES 0x0001
#define PIPE_Q_IS_RED 0x0002
#define PIPE_Q_IS_GRED 0x0004
#define PIPE_HAS_FLOW_MASK 0x0008
/* Parameters for RED and gentle RED*/
typedef struct {
/* from ip_dummynet.h*/
int w_q ; /* queue weight (scaled) */
int max_th ; /* maximum threshold for queue (scaled) */
int min_th ; /* minimum threshold for queue (scaled) */
int max_p ; /* maximum value for p_b (scaled) */
} structRed_params;
/* Pipe parameter structures*/
typedef struct {
int delay; /* pipe delay*/
int bw; /* pipe bw*/
int plr; /* queue loss rate*/
int q_size; /* queuq size in slots/bytes*/
structRed_params red_gred_params; /* red/gred params*/
#if REAL_WORLD
struct ipfw_flow_id id ; /* flow mask of the pipe*/
#endif
int buckets; /* number of buckets*/
int n_qs; /* number of dynamic queues */
u_short flags_p;
}structpipe_params, *structpipe_params_t;
/* This structure maps the linkname (eg. link0 ) to the physical
interfaces(eg. fxp0) and to the pipe numbers created at the start of
the experiment.
Later as events are recd. this table tells which pipe configuration should
be modified
*/
typedef struct {
char *linkname; /*link0, link1 etc*/
char *interfaces[2];/* fxp0, fxp1 etc*/
char *linktype; /*simplex, duplex */
int pipes[2]; /* array of pipe numbers*/
structpipe_params params[2]; /* params for the two pipes*/
}structlink_map, * structlink_map_t;
/*************************USER DEFINED TYPES********************************/
/******************************Function prototypes******************************/
void usage(char *);
void fill_tuple(address_tuple_t);
void agent_callback(event_handle_t handle,
event_notification_t notification, void *data);
void handle_event(char* , char* , event_notification_t ,event_handle_t);
void handle_link_modify(char *objname, event_handle_t handle,
event_notification_t notification);
void handle_link_up (char* linkname);
void handle_link_down (char* linkname);
int check_object(char* objname);
int search(char * objname);
void dump_link_map();
/******************************Function prototypes******************************/
#endif /*__AGENT_MAIN_DUMMY_H*/
/*
* agent-main.h --
*
* Delay node agent data structures
*
*
* @COPYRIGHT@
*/
#ifndef __AGENT_MAIN_H
#define __AGENT_MAIN_H
/*************************INCLUDES******************************************/
/* for setsockopt and stuff */
#include <sys/param.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <grp.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sysexits.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_fw.h>
#include <net/route.h> /* def. of struct route */
#include <netinet/ip_dummynet.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
/* for setsockopt and stuff */
#include <stdio.h>
#include <unistd.h>
#include "event.h"
#include "tbdefs.h"
#include "log.h"
#if 0
#include "tbdb.h"
#endif
#if 0
/* these are defined in testbed/lib/libtb/tbdb.h, will include
that directory later and then throw out these defines
*/
#define TBDB_OBJECTTYPE_LINK "LINK"
#define TBDB_EVENTTYPE_UP "UP"
#define TBDB_EVENTTYPE_DOWN "DOWN"
#define TBDB_EVENTTYPE_MODIFY "MODIFY"
#endif
/*************************INCLUDES******************************************/
/**************************DEFINES******************************************/
#define MAX_LINE_LENGTH 256
#define MAX_LINKS 4 /* 4 simplex or 2 duplex, since we have 4 interfaces
on delay nodes*/
/**************************DEFINES******************************************/
/*************************USER DEFINED TYPES********************************/
/* flag bits which indicate pipe parameters*/
#define PIPE_QSIZE_IN_BYTES 0x0001
#define PIPE_Q_IS_RED 0x0002
#define PIPE_Q_IS_GRED 0x0004
#define PIPE_HAS_FLOW_MASK 0x0008
/* Parameters for RED and gentle RED*/
typedef struct {
/* from ip_dummynet.h*/
int w_q ; /* queue weight (scaled) */
int max_th ; /* maximum threshold for queue (scaled) */
int min_th ; /* minimum threshold for queue (scaled) */
int max_p ; /* maximum value for p_b (scaled) */
} structRed_params;
/* link status*/
typedef enum {
LINK_UP = 0,
LINK_DOWN
}enumlinkstat;
/* Pipe parameter structures*/
typedef struct {
int delay; /* pipe delay*/
int bw; /* pipe bw*/
double plr; /* queue loss rate*/
int q_size; /* queuq size in slots/bytes*/
structRed_params red_gred_params; /* red/gred params*/
struct ipfw_flow_id id ; /* flow mask of the pipe*/
int buckets; /* number of buckets*/
int n_qs; /* number of dynamic queues */
u_short flags_p;
}structpipe_params, *structpipe_params_t;
/* This structure maps the linkname (eg. link0 ) to the physical
interfaces(eg. fxp0) and to the pipe numbers created at the start of
the experiment.
Later as events are recd. this table tells which pipe configuration should
be modified
*/
typedef struct {
char *linkname; /*link0, link1 etc*/
char *interfaces[2];/* fxp0, fxp1 etc*/
char *linktype; /*simplex, duplex */
int pipes[2]; /* array of pipe numbers*/
structpipe_params params[2]; /* params for the two pipes*/
enumlinkstat stat; /* link status : UP/DOWN*/
}structlink_map, * structlink_map_t;
/*************************USER DEFINED TYPES********************************/
/******************************Function prototypes******************************/
void usage(char *);
void fill_tuple(address_tuple_t);
void agent_callback(event_handle_t handle,
event_notification_t notification, void *data);
void handle_pipes (char *objname, char *eventtype, event_notification_t
,event_handle_t, int);
int checkevent (char *);
int search(char* objname);
int check_object(char* objname);
void handle_link_up(char * linkname, int l_index);
void handle_link_down(char * linkname, int l_index);
void handle_link_modify(char * linkname, int l_index,
event_handle_t handle,
event_notification_t notification);
int get_link_params(int l_index);
void get_flowset_params(struct dn_flow_set*, int, int);
void get_queue_params(struct dn_flow_set*,int, int);
void set_link_params(int l_index, int blackhole);
int get_new_link_params(int l_index, event_handle_t handle,
event_notification_t notification);
void dump_link_map();
int get_link_info();
/******************************Function prototypes******************************/
#endif /*__AGENT_MAIN_H*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment