43 #ifdef IBRDTN_SUPPORT_BSP
51 #include <ibrcommon/Logger.h>
52 #include <ibrcommon/link/LinkManager.h>
53 #include <ibrcommon/link/LinkEvent.h>
54 #include <ibrcommon/thread/RWLock.h>
73 std::string buffer =
"";
81 if (buffer.length() == 0)
continue;
84 std::string::reverse_iterator iter = buffer.rbegin();
85 if ( (*iter) ==
'\r' ) buffer = buffer.substr(0, buffer.length() - 1);
88 if (cmd.empty())
continue;
115 void ManagementConnection::processCommand(
const std::vector<std::string> &cmd)
127 virtual bool shouldAdd(
const dtn::data::MetaBundle&)
const throw (dtn::storage::BundleSelectorException)
134 if (cmd[0] ==
"neighbor")
136 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
138 if (cmd[1] ==
"list")
143 for (std::set<dtn::core::Node>::const_iterator iter = nlist.begin(); iter != nlist.end(); ++iter)
145 _stream << (*iter).getEID().getString() << std::endl;
154 else if (cmd[0] ==
"interface")
156 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
158 if (cmd[1] ==
"address")
161 ibrcommon::LinkManager &lm = ibrcommon::LinkManager::getInstance();
164 ibrcommon::vinterface iface(cmd[3]);
170 ibrcommon::vaddress addr(cmd[5],
"");
172 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
176 ibrcommon::LinkEvent evt(ibrcommon::LinkEvent::ACTION_ADDRESS_ADDED, iface, addr);
180 else if (cmd[2] ==
"del")
182 ibrcommon::LinkEvent evt(ibrcommon::LinkEvent::ACTION_ADDRESS_REMOVED, iface, addr);
190 }
catch (
const std::bad_cast&) {
199 else if (cmd[0] ==
"connection")
201 if (cmd.size() < 5)
throw ibrcommon::Exception(
"not enough parameters");
209 if (cmd.size() > 6) {
210 if (cmd[6] ==
"global") {
219 if (cmd.size() < 6)
throw ibrcommon::Exception(
"not enough parameters");
223 std::string uri =
"ip=" + cmd[4] +
";port=" + cmd[5] +
";";
229 else if (cmd[3] ==
"del")
231 std::string uri =
"ip=" + cmd[4] +
";port=" + cmd[5] +
";";
238 else if (cmd[2] ==
"udp")
240 if (cmd.size() < 6)
throw ibrcommon::Exception(
"not enough parameters");
244 std::string uri =
"ip=" + cmd[4] +
";port=" + cmd[5] +
";";
250 else if (cmd[3] ==
"del")
252 std::string uri =
"ip=" + cmd[4] +
";port=" + cmd[5] +
";";
259 else if (cmd[2] ==
"file")
268 else if (cmd[3] ==
"del")
277 else if (cmd[0] ==
"logcat")
279 ibrcommon::Logger::writeBuffer(
_stream);
282 else if (cmd[0] ==
"logstream")
284 ibrcommon::Logger::addStream(
_stream, ibrcommon::Logger::LOGGER_ALL, ibrcommon::Logger::LOG_TIMESTAMP | ibrcommon::Logger::LOG_TAG | ibrcommon::Logger::LOG_LEVEL);
286 std::string buffer =
"";
289 ibrcommon::Logger::removeStream(
_stream);
292 else if (cmd[0] ==
"core")
294 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
296 if (cmd[1] ==
"shutdown")
302 else if (cmd[1] ==
"reload")
308 else if (cmd[1] ==
"low-energy")
314 else if (cmd[1] ==
"normal")
320 else if (cmd[1] ==
"start_discovery")
326 else if (cmd[1] ==
"stop_discovery")
332 else if (cmd[1] ==
"internet_off")
338 else if (cmd[1] ==
"internet_on")
345 else if (cmd[0] ==
"bundle")
347 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
349 if (cmd[1] ==
"list")
361 for (std::list<dtn::data::MetaBundle>::const_iterator iter = blist.begin(); iter != blist.end(); ++iter)
371 else if (cmd[1] ==
"clear")
378 else if (cmd[0] ==
"routing")
380 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
382 if ( cmd[1] ==
"prophet" )
390 dtn::routing::BaseRouter::extension_list::const_iterator it;
394 for(it = routingExtensions.begin(); it != routingExtensions.end(); ++it)
400 if ( cmd[2] ==
"info" ){
401 ibrcommon::ThreadsafeReference<const dtn::routing::DeliveryPredictabilityMap> dp_map = prophet_extension.
getDeliveryPredictabilityMap();
404 _stream << *dp_map << std::endl;
405 }
else if ( cmd[2] ==
"acknowledgements" ) {
406 ibrcommon::ThreadsafeReference<const dtn::routing::AcknowledgementSet> ack_set = prophet_extension.
getAcknowledgementSet();
416 throw ibrcommon::Exception(
"malformed command");
420 }
catch (
const std::bad_cast&) { }
422 if(it == routingExtensions.end())
427 }
else if ( cmd[1] ==
"static" ) {
428 if (cmd.size() < 5)
throw ibrcommon::Exception(
"not enough parameters");
435 else if (cmd[2] ==
"del")
441 throw ibrcommon::Exception(
"malformed command");
444 else if (cmd[0] ==
"stats")
446 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
448 if ( cmd[1] ==
"info" ) {
454 }
else if ( cmd[1] ==
"timesync" ) {
464 _stream <<
"Psi: " << std::setprecision(16) << state.
psi << std::endl;
465 _stream <<
"Sigma: " << std::setprecision(16) << state.
sigma << std::endl;
469 }
else if ( cmd[1] ==
"bundles" ) {
479 }
else if ( cmd[1] ==
"convergencelayers" ) {
485 for (dtn::net::ConvergenceLayer::stats_data::const_iterator iter = data.begin(); iter != data.end(); ++iter) {
487 _stream << pair.first <<
": " << pair.second << std::endl;
490 }
else if ( cmd[1] ==
"reset" ) {
503 throw ibrcommon::Exception(
"malformed command");
506 #ifdef IBRDTN_SUPPORT_BSP
507 else if (cmd[0] ==
"key-exchange")
509 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
513 if (cmd[1] ==
"none")
520 else if (cmd[1] ==
"dh")
527 else if (cmd[1] ==
"jpake")
529 if (cmd.size() < 4)
throw ibrcommon::Exception(
"password required");
540 else if (cmd[1] ==
"hash")
547 else if (cmd[1] ==
"password")
549 if (cmd.size() < 4)
throw ibrcommon::Exception(
"password required");
554 kedata.setSessionId(atoi(cmd[3].c_str()));
563 else if (cmd[1] ==
"hashcompare")
565 if (cmd.size() < 4)
throw ibrcommon::Exception(
"selection required");
566 if (cmd[4] !=
"0" && cmd[4] !=
"1")
throw ibrcommon::Exception(
"wrong value");
571 kedata.setSessionId(atoi(cmd[3].c_str()));
574 kedata.setStep(atoi(cmd[4].c_str()));
580 else if (cmd[1] ==
"newkey")
582 if (cmd.size() < 4)
throw ibrcommon::Exception(
"selection required");
583 if (cmd[4] !=
"0" && cmd[4] !=
"1")
throw ibrcommon::Exception(
"wrong value");
588 kedata.setSessionId(atoi(cmd[3].c_str()));
591 kedata.setStep(atoi(cmd[4].c_str()));
595 if (kedata.getStep() == 0) {
603 throw ibrcommon::Exception(
"malformed command");
611 }
catch (
const std::exception&) {
std::string toString() const
const extension_list & getExtensions() const
const std::set< dtn::core::Node > getNeighbors()
virtual ~ManagementConnection()
dtn::data::Length size() const
ibrcommon::RWMutex & getExtensionMutex()
std::set< RoutingExtension * > extension_list
dtn::routing::BaseRouter & getRouter() const
void setGloballyConnected(bool val)
std::pair< string, string > stats_pair
void remove(const dtn::core::Node &n)
virtual dtn::data::Size count()
void getStats(dtn::net::ConvergenceLayer::stats_data &data)
void addRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop, const dtn::data::Timeout timeout=0)
static void resetCounter()
dtn::net::ConnectionManager & getConnectionManager()
void add(const dtn::core::Node &n)
std::string toString() const
static void raise(const Action a)
ManagementConnection(ClientHandler &client, ibrcommon::socketstream &stream)
ibrcommon::ThreadsafeReference< const AcknowledgementSet > getAcknowledgementSet() const
static dtn::data::Timestamp getUptime()
static double toDouble(const timeval &val)
std::map< string, string > stats_data
static dtn::data::Timestamp getTime()
virtual dtn::data::Bundle get(const dtn::data::BundleID &id)=0
void removeRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop)
static const struct timeval & getOffset()
ibrcommon::ThreadsafeReference< DeliveryPredictabilityMap > getDeliveryPredictabilityMap()
static double getRating()
std::string getString() const
dtn::data::BundleList::const_iterator const_iterator
static const TimeSyncState & getState()
dtn::storage::BundleStorage & getStorage()
ibrcommon::socketstream & _stream
Routing extension for PRoPHET routing.
static std::vector< std::string > tokenize(const std::string &token, const std::string &data, const std::string::size_type max=std::string::npos)
static BundleCore & getInstance()
static void raise(const dtn::data::EID &eid, const dtn::security::KeyExchangeData &data)
static size_t getCounter()