N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/server/protocols/null.cpp

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 
00036 #include "mac_lib.h"
00037 
00038 
00039 long long null_throughput(void)
00040 {
00041         return 1;
00042 }
00043 
00044 
00045 int null_filter(struct oq_req_resp *rr)
00046 {
00047         if (rr == NULL)
00048                 return -1;
00049 
00050         rr->num_msgs = 1;
00051         rr->msgs[0].code = OQ_SKB_PASS;
00052         return 0;
00053 }
00054 
00055 
00056 /********************/
00057 
00058 
00059 int protocol_filter(char *name, struct oq_req_resp *rr)
00060 {
00061         struct protocol_entry *entry = 
00062           (struct protocol_entry *) &protocol_table;
00063         mac_filter_t filter = NULL;
00064 
00065         while (entry != NULL) {
00066                 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00067                         filter = entry->mac_filter;
00068                         break;
00069                 }
00070                 entry = entry->next;
00071         }
00072         if (filter != NULL)
00073                 return (*filter)(rr);
00074 
00075         return -INT_MAX;
00076 }
00077 
00078 
00079 long long protocol_throughput(char *name)
00080 {
00081         struct protocol_entry *entry = 
00082           (struct protocol_entry *) &protocol_table;
00083         mac_throughput_t thru = NULL;
00084         
00085         while (entry != NULL) {
00086                 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00087                         thru = entry->mac_throughput;
00088                         break;
00089                 }
00090                 entry = entry->next;
00091         }
00092         if (thru != NULL)
00093                 return (*thru)();
00094 
00095         return -1;
00096 }
00097 
00098 
00099 
00100 void add_protocol(char *path, char *name, char *filter, char *through)
00101 {
00102         void *lib;
00103         struct protocol_entry *entry = 
00104           (struct protocol_entry *) &protocol_table;
00105 
00106         while (entry->next != NULL)
00107                 entry = entry->next;
00108 
00109         if ((lib = dlopen(path, RTLD_LAZY)) != NULL) {
00110                 struct protocol_entry *next_entry = (struct protocol_entry *) 
00111                         malloc(sizeof(struct protocol_entry));
00112                 strncpy(next_entry->name, name, MAX_NAME);
00113                 next_entry->mac_filter = (mac_filter_t) dlsym(lib, filter);
00114                 next_entry->mac_throughput = 
00115                         (mac_throughput_t) dlsym(lib, through);
00116                 next_entry->next = NULL;
00117                 entry->next = next_entry;
00118         }
00119 }
00120 
00121 
00122 void remove_protocol(char *name)
00123 {
00124         struct protocol_entry *entry = protocol_table.next;
00125         struct protocol_entry *prev = 
00126           (struct protocol_entry *) &protocol_table;
00127 
00128         if (strncmp(name, "null", 4))
00129                 return;
00130 
00131         while (entry != NULL) {
00132                 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00133                         prev->next = entry->next;
00134                         free(entry);
00135                         break;
00136                 }
00137                 prev = entry;
00138                 entry = entry->next;
00139         }
00140 }


© 2007, Los Alamos National Security, LLC.