00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <oasys/util/StringBuffer.h>
00019
00020 #include "bundling/BundleEvent.h"
00021 #include "contacts/Contact.h"
00022 #include "routing/RouteTable.h"
00023 #include "routing/BundleRouter.h"
00024 #include "SimEvent.h"
00025 #include "Simulator.h"
00026 #include "Simdtn2Command.h"
00027 #include "SimConvergenceLayer.h"
00028
00029 namespace dtnsim {
00030
00031 Simdtn2Command Simdtn2Command::instance_;
00032
00033 Simdtn2Command::Simdtn2Command()
00034 : AutoTclCommand("simdtn2")
00035 {}
00036
00037 void
00038 Simdtn2Command::at_reg()
00039 {
00040 bind_s("type", &BundleRouter::type_, "static");
00041 }
00042
00043 const char*
00044 Simdtn2Command::help_string()
00045 {
00046 return "simdtn2 <time> addroute <src> <dest> <contact_id> \n";
00047
00048 }
00049
00050 int
00051 Simdtn2Command::exec(int argc, const char** argv, Tcl_Interp* interp)
00052 {
00053 if (argc < 6) {
00054 wrong_num_args(argc, argv, 2, 6, INT_MAX);
00055 return TCL_ERROR;
00056 }
00057
00058 long time = atoi(argv[1]) ;
00059 const char* cmd = argv[2];
00060 const char* src_str = argv[3];
00061 const char* dest_str = argv[4];
00062 const char* next_hop_str = argv[5];
00063
00064 if (strcmp(cmd, "addroute") == 0) {
00065
00066 int cid = atoi(next_hop_str);
00067 SimContact* link = Topology::contact(cid);
00068 Contact* contact = SimConvergenceLayer::simlink2ct(link);
00069 ASSERT(contact != NULL);
00070
00071 std::string dest_str_full =
00072 SimConvergenceLayer::id2node(atoi(dest_str));
00073 EndpointIDPattern dest(dest_str_full);
00074 RouteEntry* entry = new RouteEntry(dest, contact,
00075 ForwardingInfo::COPY_ACTION);
00076
00077 log_info("addroute to dest %s using contact id %d",
00078 dest_str_full.c_str(), cid);
00079
00080 int src = atoi(src_str);
00081 Event_for_br* e =
00082 new Event_for_br(time,Topology::node(src),new RouteAddEvent(entry));
00083 Simulator::post(e);
00084
00085 }
00086 else {
00087 PANIC("unimplemented command");
00088 }
00089
00090 return TCL_OK;
00091 }
00092
00093 }