00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "Python.h"
00032 #include "structmember.h"
00033
00034 #include "EpidemicStore.h"
00035 #include "EpidemicApp.h"
00036 #include "EpidemicForwarding.h"
00037 #include "EpidemicCustody.h"
00038
00039 #include "mobility/MobileNode.h"
00040 #include "mobility/WirelessLink.h"
00041 #include "pydtn/parsers.h"
00042 #include "mobility/parsers.h"
00043 #include "simlpy/interpreter_hooks.h"
00044 #include "simlpy/Clock.h"
00045
00052 #ifndef PyMODINIT_FUNC
00055 #define PyMODINIT_FUNC extern "C" void
00056 #endif
00057
00059 static uint32_t epidemic_max_hops = 0;
00060
00064 static char epidemic_set_max_hops_doc[] =
00065 "Set the maximum number of allowed hops.\n\
00066 \n\
00067 This takes one integer argument, which will set the number\n\
00068 of hops that a bundle may take via epidemic forwarding\n\
00069 before further propagation is limited to the destination\n\
00070 node. The default value is 0, which is unlimited forwarding.\n";
00071
00078 static PyObject*
00079 epidemic_set_max_hops( PyObject* self, PyObject* args )
00080 {
00081 if ( ! PyTuple_Check( args ) )
00082 {
00083 PyErr_SetString(PyExc_TypeError,
00084 "set_max_hops expects a list of arguments");
00085 return 0;
00086 }
00087 if ( 0 == PyTuple_Size( args ) )
00088 {
00089 PyErr_SetString(PyExc_TypeError,
00090 "set_max_hops expects an argument");
00091 return 0;
00092 }
00093
00094 try
00095 {
00096 long int val = parse_long( PyTuple_GetItem(args,0) );
00097 epidemic_max_hops = val;
00098 }
00099 catch ( ... )
00100 {
00101 PyErr_SetString(PyExc_TypeError,"integer expected");
00102 return 0;
00103 }
00104
00105 Py_INCREF(Py_None);
00106 return Py_None;
00107 }
00108
00112 static char epidemic_attach_doc[] = "Add an application instance to a node.\n\
00113 \n\
00114 Calling syntax:\n\
00115 \n\
00116 pydtn.mobility.epidemic.attach(<n>,<l>)\n\
00117 \n\
00118 <n> is a mobile node to which we want to add an instance.\n\
00119 <l> is the wireless link for the node.\n\
00120 \n\
00121 In general, this will be called automatically at node creation by\n\
00122 pydtn.mobility.node()\n";
00123
00131 static PyObject*
00132 epidemic_attach( PyObject* self, PyObject* args )
00133 {
00134 if ( ! PyTuple_Check( args ) )
00135 {
00136 PyErr_SetString(PyExc_TypeError,"attach expects a list of arguments");
00137 return 0;
00138 }
00139 if ( PyTuple_Size( args ) < 2 )
00140 {
00141 PyErr_SetString(PyExc_TypeError,
00142 "attach expects two arguments");
00143 return 0;
00144 }
00145
00146 Mobility::MobileNode* mn = Mobility::parse_mn( PyTuple_GetItem(args,0) );
00147 if ( 0 == mn ) return 0;
00148
00149 Mobility::WirelessLink* wl = Mobility::parse_wl( PyTuple_GetItem(args,1) );
00150 if ( 0 == wl ) return 0;
00151
00152 Epidemic::EpidemicStore* ps =
00153 new Epidemic::EpidemicStore( &(mn->node()), epidemic_max_hops );
00154 Epidemic::EpidemicApp* ma =
00155 new Epidemic::EpidemicApp( ps, &(wl->link()), mn->bundleLifetime().tv );
00156 Epidemic::EpidemicForwarding* fp =
00157 new Epidemic::EpidemicForwarding( &(mn->node()), &(wl->link()), ma );
00158
00159 mn->setPersistentStore(ps);
00160 mn->addMobileApp(ma);
00161 mn->setForwardingPolicy(fp);
00162 mn->node().setCustodyPolicy( new Epidemic::EpidemicCustody(&(mn->node())) );
00163
00164
00165 Py_INCREF(Py_None);
00166 return Py_None;
00167 }
00168
00171 static PyMethodDef ExampleMethods[] =
00172 {
00173 {"set_max_hops",epidemic_set_max_hops,METH_VARARGS,epidemic_set_max_hops_doc},
00174 {"attach",epidemic_attach,METH_VARARGS,epidemic_attach_doc},
00175 {0,0,0,0}
00176 };
00177
00181 PyMODINIT_FUNC
00182 init_epidemic(void)
00183 {
00184 (void) Py_InitModule("_epidemic",ExampleMethods);
00185 }
00186