servlib/cmd/ECLACommand.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /* Copyright 2004-2006 BBN Technologies Corporation
       
     2  *
       
     3  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
       
     4  * use this file except in compliance with the License. You may obtain a copy
       
     5  * of the License at http://www.apache.org/licenses/LICENSE-2.0
       
     6  *
       
     7  * Unless required by applicable law or agreed to in writing, software
       
     8  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
       
     9  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    10  *
       
    11  * See the License for the specific language governing permissions and
       
    12  * limitations under the License.
       
    13  *
       
    14  */
       
    15 
       
    16 #ifdef HAVE_CONFIG_H
       
    17 #  include <dtn-config.h>
       
    18 #endif
       
    19 
       
    20 #if defined(XERCES_C_ENABLED) && defined(EXTERNAL_CL_ENABLED)
       
    21 
       
    22 #include <oasys/io/NetUtils.h>
       
    23 
       
    24 #include "ECLACommand.h"
       
    25 #include "conv_layers/ConvergenceLayer.h"
       
    26 #include "conv_layers/ExternalConvergenceLayer.h"
       
    27 
       
    28 namespace dtn {
       
    29 
       
    30 static ExternalConvergenceLayer* ecl = NULL;
       
    31 
       
    32 ECLACommand::ECLACommand() 
       
    33     : TclCommand("ecla")
       
    34 {
       
    35     bind_var( new oasys::StringOpt("schema",
       
    36               &ExternalConvergenceLayer::schema_,
       
    37               "ECLA schema location",
       
    38               "The location of the ECLA schema file.") );
       
    39     
       
    40     bind_var( new oasys::InAddrOpt("server_addr",
       
    41               &ExternalConvergenceLayer::server_addr_,
       
    42               "ECLA server address",
       
    43               "The address to listen for external CLAs on") );
       
    44     
       
    45     bind_var( new oasys::UInt16Opt("server_port",
       
    46               &ExternalConvergenceLayer::server_port_,
       
    47               "ECLA server port",
       
    48               "The port to listen for external CLAs on") );
       
    49     
       
    50     bind_var( new oasys::BoolOpt("create_discovered_links",
       
    51               &ExternalConvergenceLayer::create_discovered_links_,
       
    52               "Whether external CLAs should create discovered links") );
       
    53     
       
    54     bind_var( new oasys::BoolOpt("discovered_prev_hop_header",
       
    55               &ExternalConvergenceLayer::discovered_prev_hop_header_,
       
    56               "Whether discovered links get prev-hop headers") );
       
    57 }
       
    58 
       
    59 int
       
    60 ECLACommand::exec(int argc, const char** argv, Tcl_Interp* interp)
       
    61 {
       
    62     (void)interp;
       
    63     
       
    64     if (argc < 2) {
       
    65         resultf("Need an ecla subcommand");
       
    66         return TCL_ERROR;
       
    67     }
       
    68 
       
    69     const char* cmd = argv[1];
       
    70 
       
    71     if (strcmp(cmd, "start") == 0) {
       
    72         if (ecl) {
       
    73             resultf("ExternalConvergenceLayer already started");
       
    74             return TCL_ERROR;
       
    75         }
       
    76         
       
    77         ecl = new ExternalConvergenceLayer();
       
    78         ecl->start();        
       
    79         ConvergenceLayer::add_clayer(ecl);
       
    80     }
       
    81     
       
    82     else {
       
    83         resultf("Unimplemented ecla subcommand %s", cmd);
       
    84         return TCL_ERROR;
       
    85     }
       
    86     
       
    87     return TCL_OK;
       
    88 }
       
    89     
       
    90 } // namespace dtn
       
    91 
       
    92 #endif // XERCES_C_ENABLED && EXTERNAL_CL_ENABLED