Simdtn2Command.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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 //      simdtn2 <time> addroute <src> <dest> <contact_id> 
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         // post the event, through the simulator 
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 } // namespace dtnsim

Generated on Sat Sep 8 08:43:33 2007 for DTN Reference Implementation by  doxygen 1.5.3