InterfaceCommand.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 "InterfaceCommand.h"
00019 #include "contacts/InterfaceTable.h"
00020 #include "conv_layers/ConvergenceLayer.h"
00021 #include <oasys/util/StringBuffer.h>
00022 
00023 namespace dtn {
00024 
00025 InterfaceCommand::InterfaceCommand()
00026     : TclCommand("interface") 
00027 {
00028     add_to_help("add <name> <conv layer> [<args>?]",
00029                 "add an interface");
00030     add_to_help("del <name>", "delete an interface");
00031     add_to_help("list", "list all of the interfaces");
00032 }
00033 
00034 int
00035 InterfaceCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00036 {
00037     (void)interp;
00038     // interface list
00039     if (strcasecmp("list", argv[1]) == 0) {
00040         // XXX/bowei -- seems to like to core
00041         if (argc > 2) {
00042             wrong_num_args(argc, argv, 1, 2, 2);
00043         }
00044 
00045         oasys::StringBuffer buf;
00046         InterfaceTable::instance()->list(&buf);
00047         set_result(buf.c_str());
00048 
00049         return TCL_OK;
00050     }
00051     
00052     // interface add <name> <conv_layer> <args>
00053     else if (strcasecmp(argv[1], "add") == 0) {
00054         if (argc < 4) {
00055             wrong_num_args(argc, argv, 1, 4, INT_MAX);
00056             return TCL_ERROR;
00057         }
00058         
00059         const char* name    = argv[2];
00060         const char* proto   = argv[3];
00061 
00062         ConvergenceLayer* cl = ConvergenceLayer::find_clayer(proto);
00063         if (!cl) {
00064             resultf("can't find convergence layer for %s", proto);
00065             return TCL_ERROR;
00066         }
00067 
00068         // XXX/demmer return error string from here
00069         if (! InterfaceTable::instance()->add(name, cl, proto,
00070                                               argc - 4, argv + 4)) {
00071             resultf("error adding interface %s", name);
00072             return TCL_ERROR;
00073         }
00074         return TCL_OK;
00075     }
00076 
00077     // interface del <name>
00078     else if (strcasecmp(argv[1], "del") == 0) {
00079         if (argc != 3) {
00080             wrong_num_args(argc, argv, 2, 4, 4);
00081             return TCL_ERROR;
00082         }
00083 
00084         const char* name = argv[2];
00085         
00086         if (! InterfaceTable::instance()->del(name)) {
00087             resultf("error removing interface %s", name);
00088             return TCL_ERROR;
00089         }
00090 
00091         return TCL_OK;
00092     }
00093     
00094     resultf("invalid interface subcommand %s", argv[1]);
00095     return TCL_ERROR;
00096 }
00097 
00098 } // namespace dtn

Generated on Sat Sep 8 08:36:17 2007 for DTN Reference Implementation by  doxygen 1.5.3