Skip to content

Commit

Permalink
[ms] finished clean up of omnet code, brought the omnet code up to da…
Browse files Browse the repository at this point in the history
…te with current version of relay code, made 2 small changes on the relay code (file ccnl_core.h:{l205,l208} added the const descriptor, file ccnl-ext-encaps.c:{l158,l159} changed var datalen to unsigned int)
  • Loading branch information
Manolis Sifalakis committed Jun 20, 2013
1 parent 2845ef6 commit 8ea368e
Show file tree
Hide file tree
Showing 15 changed files with 724 additions and 1,265 deletions.
122 changes: 59 additions & 63 deletions ccn-lite-omnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define LOG_LEVEL_4_OMNET 50 // set the log level for debug info piped to Omnet's EV.
// (this is independent of 'log_level' in b3c-relay-debug.c
// which controls what is reported in stderr)
#define USE_ENCAPS // ? TODO - Ask Christian, is this needed only for the fragmentation ?
#define USE_ENCAPS // for pkt fragmentation
#define USE_ETHERNET

#define USE_SCHEDULER // enable relay scheduling capabilities (e.g. for inter-packet pacing)
Expand All @@ -48,36 +48,14 @@
#define PROPAGATE_INTERESTS_SEEN_BEFORE // if a received interest already exists in the PIT,
// it is not forwarded. Use this option to override this

// TODO -- What happens if the cache memory is full ? (Cache replacemnet strategy)
#define CONTENT_NEVER_EXPIRES // content never deleted from the cache memory unless full



/* TODO - MUST BE CHECKED FOR COMPLIANCE - -- Manolis: Ask Christian about adding the following as an option
* (brought forward from old code)
*
#define SERVE_EXACT_MATCH_CONTENT_ONLY // loose match of the content name do not deliver the content
*
* requires the following modification in ccn-relay.c:779/ccnl_content_serve_pending() as well as
* other places where ccnl_prefix_cmp() is used
*
#if defined(SERVE_EXACT_MATCH_CONTENT_ONLY)
int rc = ccnl_prefix_cmp(c->prefix, i->prefix, EXACT_MATCH);
#else
int rc = ccnl_prefix_cmp(c->prefix, i->prefix, LOOSE_MATCH);
#endif
*
*/



/*****************************************************************************
*
* API used by Omnet to communicate with CCN Lite (forward declarations)
*
* TODO: make these functions return an error code, so that I can block the
* simulation in case of errors
*
*****************************************************************************/


Expand All @@ -96,28 +74,28 @@ void * ccnl_create_relay ( /* mgmt */
int tx_pace
);

void ccnl_add_content ( /* mgmt */
int ccnl_add_content ( /* mgmt */
void *relay,
const char *name,
int seqn,
void *data,
int len
);

void ccnl_add_fwdrule( /* mgmt */
int ccnl_add_fwdrule( /* mgmt */
void *relay,
const char *name,
const char *dst,
int netif_idx
);

void ccnl_app2relay( /* data */
int ccnl_app2relay( /* data */
void *relay,
const char *name,
int seqn
);

void ccnl_lnk2relay( /* data */
int ccnl_lnk2relay( /* data */
void *relay,
const char *dst,
const char *src,
Expand Down Expand Up @@ -578,7 +556,7 @@ ccnl_set_absolute_timer (
* callback for time progression
*/
void
ccnl_ageing(void *relay, void *aux) // TODO -- this replaces the do_ageing callback in v0, adapt the v0 to this
ccnl_ageing(void *relay, void *aux)
{
if (!relay) return;

Expand Down Expand Up @@ -629,8 +607,6 @@ ccnl_destroy_relay (void *relay)
}
ccnl_free(active_relay);


// TODO - no chemflow for now, is there anything else to clean up for the scheduler ?
//ccnl_sched_cleanup();

#ifdef CCNL_DEBUG_MALLOC
Expand Down Expand Up @@ -699,7 +675,7 @@ ccnl_create_relay (
}


/* init eth[i] interfaces (one for each MAC addr we have)
/* init struct ccnl_if_s for each eth[i] interface (one for each MAC addr we are given)
*/
for (int k=0 ; k < num_mac_ifs ; k++ )
{
Expand All @@ -714,8 +690,6 @@ ccnl_create_relay (
i->sched = ccnl_sched_pktrate_new (ccnl_interface_CTS, new_relay, tx_pace);
#endif // USE_SCHEDULER

//i->encaps = CCNL_ENCAPS_SEQUENCED2012; // TODO -- Ask cft what this does !

#ifdef PROPAGATE_INTERESTS_SEEN_BEFORE
i->fwdalli = 1;
#endif // PROPAGATE_INTERESTS_SEEN_BEFORE
Expand All @@ -724,11 +698,6 @@ ccnl_create_relay (
};


/* TODO -- init sock[i] interfaces (one for each socket addr we have)
*/
// ...


/* no scheduling at the face level (only at the interface level for tx pacing)
* TODO: think if I need to enable such a possibility for simu testing
*/
Expand Down Expand Up @@ -758,7 +727,7 @@ ccnl_create_relay (
/*****************************************************************************
* store a content chunk to relay's CS
*/
void
int
ccnl_add_content (
void *relay,
const char *name,
Expand All @@ -768,10 +737,10 @@ ccnl_add_content (
)
{
active_relay = (struct ccnl_relay_s *) relay;
if (!active_relay) return;
if (!active_relay) return -1;

struct ccnl_omnet_s *opp_info = (struct ccnl_omnet_s *) active_relay->aux;
if (!opp_info) return;
if (!opp_info) return -1;

struct ccnl_buf_s *bp;
struct ccnl_prefix_s *pp;
Expand All @@ -795,13 +764,20 @@ ccnl_add_content (
len2 = mkContent(namecomp, (char *) data, len, tmp2);
free(n);

bp = ccnl_buf_new(tmp2, len2);
// ms: failed, free and ret
if ( ! (bp = ccnl_buf_new(tmp2, len2)))
return -1;

strcpy((char*) tmp2, name);
sprintf(tmp, "/.%d", seqn);
strcat((char*) tmp2, tmp);

pp = ccnl_path_to_prefix((const char*)tmp2);
// ms: failure, free and ret
if ( ! (pp = ccnl_path_to_prefix((const char*)tmp2)) )
{
ccnl_free(bp);
return -1;
};

c = ccnl_content_new((struct ccnl_relay_s *) relay, &bp, &pp, NULL, 0, 0);

Expand All @@ -811,30 +787,34 @@ ccnl_add_content (
#endif
ccnl_content_add2cache((struct ccnl_relay_s *) relay, c);
}
else { //ms: failure, free and ret
ccnl_free(pp);
ccnl_free(bp);
return -1;
}

DEBUGMSG(99, "ccnl_add_content %s in relay of node %s (%d) \n", tmp2, opp_info->node_name, opp_info->node_id);

return;
return 0;
};


/*****************************************************************************
* add a forwarding rule in relay's FIB
*/
void
int
ccnl_add_fwdrule(
void *relay,
const char *name,
const char *dstaddr,
int netif_idx
)
{

active_relay = (struct ccnl_relay_s *) relay;
if (!active_relay) return;
if (!active_relay) return -1;

struct ccnl_omnet_s *opp_info = (struct ccnl_omnet_s *) active_relay->aux;
if (!opp_info) return;
if (!opp_info) return -1;

struct ccnl_forward_s *fwd;
sockunion sun;
Expand All @@ -848,42 +828,58 @@ ccnl_add_fwdrule(
sun.eth.sll_family = AF_PACKET;
memcpy(sun.eth.sll_addr, dstaddr, ETH_ALEN);
fwd = (struct ccnl_forward_s *) ccnl_calloc(1, sizeof(*fwd));
fwd->prefix = ccnl_path_to_prefix(name);

if ( !(fwd->prefix = ccnl_path_to_prefix(name)))
{
ccnl_free(fwd);
return -1;
};

fwd->face = ccnl_get_face_or_create(
(struct ccnl_relay_s *) relay,
netif_idx,
&sun.sa,
sizeof(sun.eth),
CCNL_ENCAPS_SEQUENCED2012);
fwd->face->flags |= CCNL_FACE_FLAGS_STATIC; // TODO -- Check what is this ?
sizeof(sun.eth));
#ifdef USE_ENCAPS
if ( !fwd->face->encaps ) // if newly created face, no fragment policy is defined yet
fwd->face->encaps = ccnl_encaps_new(CCNL_ENCAPS_CCNPDU2013, 1200);
#endif

if (! (fwd->face))
{
ccnl_free(fwd->prefix);
ccnl_free(fwd);
return -1;
}

fwd->face->flags |= CCNL_FACE_FLAGS_STATIC; // TODO -- ?
fwd->next = ((struct ccnl_relay_s *) relay)->fib;
((struct ccnl_relay_s *) relay)->fib = fwd;

return;
return 0;
};


/*****************************************************************************
* higher layer (omnet) passes to relay
*/
void
int
ccnl_app2relay(
void *relay,
const char *name,
int seqn
)
{

char *namecomp[20], *n, *cname;
char tmp[512], tmp2[10];
int len, cnt;
int nonce = rand(); // is this ok ? Is the application only checking that or the protocol too ?

active_relay = (struct ccnl_relay_s *) relay;
if (!active_relay) return;
if (!active_relay) return -1;

struct ccnl_omnet_s *opp_info = (struct ccnl_omnet_s *) active_relay->aux;
if (!opp_info) return;
if (!opp_info) return -1;

DEBUGMSG(10, "ccnl_app2relay on node %s (%d) requests content %s (chunk %d)\n", opp_info->node_name, opp_info->node_id, name, seqn);

Expand All @@ -905,21 +901,21 @@ ccnl_app2relay(
/* ccnb for Interest pkt
*/
len = mkInterest(namecomp, (unsigned int *) &nonce, (unsigned char*) tmp);
ccnl_free(n);
free(n);

/* pass it to relay
*/
ccnl_core_RX((struct ccnl_relay_s *) relay, -1, (unsigned char*)tmp, len, 0, 0);

return;
return 0;
};



/*****************************************************************************
* lower layer (omnet) passes data to relay
*/
void
int
ccnl_lnk2relay(
void *relay,
const char *dst,
Expand All @@ -932,10 +928,10 @@ ccnl_lnk2relay(
sockunion sun;

active_relay = (struct ccnl_relay_s *) relay;
if (!active_relay) return;
if (!active_relay) return -1;

struct ccnl_omnet_s *opp_info = (struct ccnl_omnet_s *) active_relay->aux;
if (!opp_info) return;
if (!opp_info) return -1;

DEBUGMSG(10, "ccnl_lnk2relay on node %s (%d) received %d bytes of data on netif %d from %s destined to %s \n",
opp_info->node_name,
Expand All @@ -958,7 +954,7 @@ ccnl_lnk2relay(
&sun.sa,
sizeof(sun.eth));

return;
return 0;
};


Expand Down
4 changes: 2 additions & 2 deletions ccnl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ struct ccnl_content_s {
// ----------------------------------------------------------------------
// collect the USE_* macros in a string

inline char*
inline const char*
compile_string(void)
{
static char *cp = ""
static const char *cp = ""
#ifdef USE_DEBUG
"USE_DEBUG "
#endif
Expand Down
3 changes: 2 additions & 1 deletion ccnl-ext-encaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ ccnl_encaps_mknextfragment(struct ccnl_encaps_s *e, int *ifndx,
{
struct ccnl_buf_s *buf = 0;
unsigned char header[256];
int hdrlen = 0, blobtaglen, datalen, flagoffs;
int hdrlen = 0, blobtaglen, flagoffs;
unsigned int datalen;
DEBUGMSG(16, "ccnl_encaps_mknextfragment e=%p, mtu=%d\n", (void*)e, e->mtu);

if (!e->bigpkt) {
Expand Down
5 changes: 3 additions & 2 deletions omnet/simulations/example1/omnetpp.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ description = "Example CCN over Ethernet Tau topology with 2 clients, 2 routers,

## topology/scenario settings
*.defaultDebugLevel = 3 ## for all simulation: 0=none, 1=Info, 2=Warning, 3=Error, 4=Detail
*.auxDebug = true ## enable console debugging output

## per node settings
**.debugLevel = 5 ## per host: 0=none, 1=Info, 2=Warning, 3=Error, 4=Detail
**.minTxPace = 0ms
**.debugLevel = 4 ## per host: 0=none, 1=Info, 2=Warning, 3=Error, 4=Detail
**.minTxPace = 10ms
**.maxCacheSlots = 400
**.maxCacheBytes = 524288000Bytes
**.ccnCoreVersion = "CcnLite.v1"
Expand Down
Loading

0 comments on commit 8ea368e

Please sign in to comment.