Browse Source
used boost::property_tree::info_parser for parsing nlsr's configuration file and changed configuration command style to info command style. Removed tokenizer from nlsr Refs: #1542 Change-Id: If017ddd7eef5caa59b33940bfc27a71aa4de266bpull/1/head
50 changed files with 1417 additions and 1913 deletions
@ -1,14 +1,97 @@
|
||||
network ndn |
||||
site-name memphis.edu |
||||
router-name cs/macbook |
||||
; the general section contains all the general settings for router |
||||
|
||||
ndnneighbor /ndn/memphis.edu/cs/maia 7 |
||||
link-cost /ndn/memphis.edu/cs/maia 30 |
||||
ndnneighbor /ndn/memphis.edu/cs/pollux 10 |
||||
link-cost /ndn/memphis.edu/cs/pollux 25 |
||||
general |
||||
{ |
||||
; mandatory configuration command section network, site and router |
||||
|
||||
ndnname /ndn/memphis.edu/cs/macbook/name1 |
||||
ndnname /ndn/memphis.edu/cs/macbook/name2 |
||||
network /ndn/ ; name of the network the router belongs to in ndn URI format |
||||
site /memphis.edu/ ; name of the site the router belongs to in ndn URI format |
||||
router /cs/pollux/ ; name of the network the router belongs to in ndn URI format |
||||
|
||||
; lsa-refresh-time is the time in seconds, after which router will refresh its LSAs |
||||
|
||||
!logdir /Users/akmhoque/NLSR-CPP/log |
||||
lsa-refresh-time 1800 ; default value 1800. Valid values 240-7200 |
||||
|
||||
; log-level is to set the levels of log for NLSR |
||||
|
||||
log-level INFO ; default value INFO, valid value DEBUG, INFO |
||||
} |
||||
|
||||
; the neighbors section contains the configuration for router's neighbors and hello's behavior |
||||
|
||||
neighbors |
||||
{ |
||||
; in case hello interest timed out, router will try 'hello-retries' times at 'hello-time-out' |
||||
; seconds interval before giving up for any neighbors (deciding link is down) |
||||
|
||||
hello-retries 3 ; interest retries number in integer. Default value 3 |
||||
; valid values 1-10 |
||||
|
||||
hello-timeout 1 ; interest time out value in integer. Default value 1 |
||||
; Valid values 1-15 |
||||
|
||||
hello-interval 60 ; interest sending interval in seconds. Default value 60 |
||||
; valid values 30-90 |
||||
; neighbor command is used to configure router's neighbor. Each neighbor will need |
||||
; one block of neighbor command |
||||
|
||||
neighbor |
||||
{ |
||||
name /ndn/memphis.edu/cs/castor ; name prefix of the neighbor router consists |
||||
; of network, site-name and router-name |
||||
|
||||
face-uri udp://castor.cs.memphis.edu ; face id of the face connected to the neighbor |
||||
link-cost 25 ; cost of the connecting link to neighbor |
||||
} |
||||
|
||||
neighbor |
||||
{ |
||||
name /ndn/memphis.edu/cs/mira ; name prefix of the neighbor router consists |
||||
; of network, site-name and router-name |
||||
|
||||
face-uri udp://mira.cs.memphis.edu ; face id of the face connected to the neighbor |
||||
link-cost 30 ; cost of the connecting link to neighbor |
||||
} |
||||
} |
||||
|
||||
; the hyperbolic section contains the configuration settings of enabling a router to calculate |
||||
; routing table using [hyperbolic routing table calculation](http://arxiv.org/abs/0805.1266) method |
||||
|
||||
hyperbolic |
||||
{ |
||||
; commands in this section follows a strict order |
||||
; the switch is used to set hyperbolic routing calculation in NLSR |
||||
|
||||
state off ; default value 'off', set value 'on' to enable hyperbolic routing table |
||||
; calculation which turns link state routing 'off'. set value to 'dry-run" |
||||
; to test hyperbolic routing and compare with link state routing. |
||||
|
||||
|
||||
radius 123.456 ; radius of the router in hyperbolic coordinate system |
||||
angle 1.45 ; angle of the router in hyperbolic coordinate system |
||||
} |
||||
|
||||
|
||||
; the fib section is used to configure fib entry's type to ndn FIB updated by NLSR |
||||
|
||||
fib |
||||
{ |
||||
; the max-faces-per-prefix is used to limit the number of faces for each name prefixes |
||||
; by NLSR in ndn FIB |
||||
|
||||
max-faces-per-prefix 3 ; default value 0. Valid value 0-60. By default (value 0) NLSR adds |
||||
; all available faces for each reachable name prefixes in NDN FIB |
||||
|
||||
} |
||||
|
||||
; the advertising section contains the configuration settings of the name prefixes |
||||
; hosted by this router |
||||
|
||||
advertising |
||||
{ |
||||
; the ndnname is used to advertised name from the router. To advertise each name prefix |
||||
; configure one block of ndnname configuration command for every name prefix. |
||||
|
||||
prefix /ndn/edu/memphis/cs/netlab ; name in ndn URI format |
||||
prefix /ndn/edu/memphis/sports/basketball |
||||
} |
||||
|
@ -1,551 +1,352 @@
|
||||
#include <iostream> |
||||
#include <fstream> |
||||
#include <string> |
||||
#include <cstdlib> |
||||
#include <sstream> |
||||
#include <boost/algorithm/string.hpp> |
||||
#include <boost/property_tree/info_parser.hpp> |
||||
#include <boost/property_tree/ptree.hpp> |
||||
|
||||
#include <ndn-cxx/name.hpp> |
||||
|
||||
#include "conf-file-processor.hpp" |
||||
#include "conf-parameter.hpp" |
||||
#include "utility/tokenizer.hpp" |
||||
#include "conf-file-processor.hpp" |
||||
#include "adjacent.hpp" |
||||
#include "utility/name-helper.hpp" |
||||
|
||||
|
||||
namespace nlsr { |
||||
|
||||
using namespace std; |
||||
|
||||
int |
||||
bool |
||||
ConfFileProcessor::processConfFile() |
||||
{ |
||||
int ret = 0; |
||||
if (!m_confFileName.empty()) |
||||
{ |
||||
std::ifstream inputFile(m_confFileName.c_str()); |
||||
if (inputFile.is_open()) |
||||
{ |
||||
for (string line; getline(inputFile, line);) |
||||
{ |
||||
if (!line.empty()) |
||||
{ |
||||
if (line[0] != '#' && line[0] != '!') |
||||
{ |
||||
ret = processConfCommand(line); |
||||
if (ret == -1) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
std::cerr << "Configuration file: (" << m_confFileName << ") does not exist :("; |
||||
std::cerr << endl; |
||||
ret = -1; |
||||
bool ret = true; |
||||
ifstream inputFile; |
||||
inputFile.open(m_confFileName.c_str()); |
||||
if (!inputFile.is_open()) { |
||||
string msg = "Failed to read configuration file: "; |
||||
msg += m_confFileName; |
||||
cerr << msg << endl; |
||||
ret = false; |
||||
} |
||||
ret = load(inputFile); |
||||
inputFile.close(); |
||||
return ret; |
||||
} |
||||
|
||||
bool |
||||
ConfFileProcessor::load(istream& input) |
||||
{ |
||||
boost::property_tree::ptree pt; |
||||
bool ret = true; |
||||
try { |
||||
boost::property_tree::read_info(input, pt); |
||||
} |
||||
catch (const boost::property_tree::info_parser_error& error) { |
||||
stringstream msg; |
||||
std::cerr << "Failed to parse configuration file " << std::endl; |
||||
std::cerr << m_confFileName << std::endl; |
||||
return false; |
||||
} |
||||
for (boost::property_tree::ptree::const_iterator tn = pt.begin(); |
||||
tn != pt.end(); ++tn) { |
||||
std::string section = tn->first; |
||||
boost::property_tree::ptree SectionAttributeTree = tn ->second; |
||||
ret = processSection(section, SectionAttributeTree); |
||||
if (ret == false) { |
||||
break; |
||||
} |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommand(string command) |
||||
bool |
||||
ConfFileProcessor::processSection(const std::string& section, |
||||
boost::property_tree::ptree SectionAttributeTree) |
||||
{ |
||||
int ret = 0; |
||||
Tokenizer nt(command, " "); |
||||
if ((nt.getFirstToken() == "network")) |
||||
{ |
||||
ret = processConfCommandNetwork(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "site-name")) |
||||
{ |
||||
ret = processConfCommandSiteName(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "root-key-prefix")) |
||||
{ |
||||
ret = processConfCommandRootKeyPrefix(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "router-name")) |
||||
{ |
||||
ret = processConfCommandRouterName(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "ndnneighbor")) |
||||
{ |
||||
ret = processConfCommandNdnNeighbor(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "link-cost")) |
||||
{ |
||||
ret = processConfCommandLinkCost(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "ndnname")) |
||||
bool ret = true; |
||||
if (section == "general") |
||||
{ |
||||
ret = processConfCommandNdnName(nt.getRestOfLine()); |
||||
ret = processConfSectionGeneral(SectionAttributeTree); |
||||
} |
||||
else if ((nt.getFirstToken() == "interest-retry-num")) |
||||
else if (section == "neighbors") |
||||
{ |
||||
processConfCommandInterestRetryNumber(nt.getRestOfLine()); |
||||
ret = processConfSectionNeighbors(SectionAttributeTree); |
||||
} |
||||
else if ((nt.getFirstToken() == "interest-resend-time")) |
||||
else if (section == "hyperbolic") |
||||
{ |
||||
processConfCommandInterestResendTime(nt.getRestOfLine()); |
||||
ret = processConfSectionHyperbolic(SectionAttributeTree); |
||||
} |
||||
else if ((nt.getFirstToken() == "lsa-refresh-time")) |
||||
else if (section == "fib") |
||||
{ |
||||
processConfCommandLsaRefreshTime(nt.getRestOfLine()); |
||||
ret = processConfSectionFib(SectionAttributeTree); |
||||
} |
||||
else if ((nt.getFirstToken() == "max-faces-per-prefix")) |
||||
else if (section == "advertising") |
||||
{ |
||||
processConfCommandMaxFacesPerPrefix(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "log-dir")) |
||||
{ |
||||
processConfCommandLogDir(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "cert-dir")) |
||||
{ |
||||
processConfCommandCertDir(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "detailed-logging")) |
||||
{ |
||||
processConfCommandDetailedLogging(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "debugging")) |
||||
{ |
||||
processConfCommandDebugging(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "chronosync-sync-prefix")) |
||||
{ |
||||
processConfCommandChronosyncSyncPrefix(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "hyperbolic-cordinate")) |
||||
{ |
||||
processConfCommandHyperbolicCordinate(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "hyperbolic-routing")) |
||||
{ |
||||
processConfCommandIsHyperbolicCalc(nt.getRestOfLine()); |
||||
} |
||||
else if ((nt.getFirstToken() == "tunnel-type")) |
||||
{ |
||||
processConfCommandTunnelType(nt.getRestOfLine()); |
||||
ret = processConfSectionAdvertising(SectionAttributeTree); |
||||
} |
||||
else |
||||
{ |
||||
cout << "Wrong configuration Command: " << nt.getFirstToken() << endl; |
||||
std::cerr << "Wrong configuration Command: " << section << std::endl; |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandNetwork(string command) |
||||
bool |
||||
ConfFileProcessor::processConfSectionGeneral(boost::property_tree::ptree |
||||
SectionAttributeTree) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Network can not be null or empty :( !" << endl; |
||||
return -1; |
||||
} |
||||
else |
||||
{ |
||||
if (command[command.size() - 1] == '/') |
||||
{ |
||||
command.erase(command.size() - 1); |
||||
try { |
||||
std::string network = SectionAttributeTree.get<string>("network"); |
||||
std::string site = SectionAttributeTree.get<string>("site"); |
||||
std::string router = SectionAttributeTree.get<string>("router"); |
||||
ndn::Name networkName(network); |
||||
if (!networkName.empty()) { |
||||
m_nlsr.getConfParameter().setNetwork(networkName); |
||||
} |
||||
if (command[0] == '/') |
||||
{ |
||||
command.erase(0, 1); |
||||
else { |
||||
cerr << " Network can not be null or empty or in bad URI format :(!" << endl; |
||||
return false; |
||||
} |
||||
m_nlsr.getConfParameter().setNetwork(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandSiteName(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << "Site name can not be null or empty :( !" << endl; |
||||
return -1; |
||||
} |
||||
else |
||||
{ |
||||
if (command[command.size() - 1] == '/') |
||||
{ |
||||
command.erase(command.size() - 1); |
||||
ndn::Name siteName(site); |
||||
if (!siteName.empty()) { |
||||
m_nlsr.getConfParameter().setSiteName(siteName); |
||||
} |
||||
if (command[0] == '/') |
||||
{ |
||||
command.erase(0, 1); |
||||
else { |
||||
cerr << "Site can not be null or empty or in bad URI format:( !" << endl; |
||||
return false; |
||||
} |
||||
m_nlsr.getConfParameter().setSiteName(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandRootKeyPrefix(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << "Root Key Prefix can not be null or empty :( !" << endl; |
||||
return -1; |
||||
} |
||||
else |
||||
{ |
||||
if (command[command.size() - 1] == '/') |
||||
{ |
||||
command.erase(command.size() - 1); |
||||
ndn::Name routerName(router); |
||||
if (!routerName.empty()) { |
||||
m_nlsr.getConfParameter().setRouterName(routerName); |
||||
} |
||||
if (command[0] == '/') |
||||
{ |
||||
command.erase(0, 1); |
||||
else { |
||||
cerr << " Router name can not be null or empty or in bad URI format:( !" << endl; |
||||
return false; |
||||
} |
||||
m_nlsr.getConfParameter().setRootKeyPrefix(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandRouterName(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Router name can not be null or empty :( !" << endl; |
||||
return -1; |
||||
catch (const std::exception& ex) { |
||||
cerr << ex.what() << endl; |
||||
return false; |
||||
} |
||||
else |
||||
{ |
||||
if (command[command.size() - 1] == '/') |
||||
{ |
||||
command.erase(command.size() - 1); |
||||
|
||||
try { |
||||
int32_t lsaRefreshTime = SectionAttributeTree.get<int32_t>("lsa-refresh-time"); |
||||
if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && |
||||
lsaRefreshTime <= LSA_REFRESH_TIME_MAX) { |
||||
m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime); |
||||
} |
||||
if (command[0] == '/') |
||||
{ |
||||
command.erase(0, 1); |
||||
else { |
||||
std::cerr << "Wrong value for lsa-refresh-time "; |
||||
std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";; |
||||
std::cerr << LSA_REFRESH_TIME_MAX << std::endl; |
||||
return false; |
||||
} |
||||
m_nlsr.getConfParameter().setRouterName(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandInterestRetryNumber(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [interest-retry-num n]" << endl; |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
else |
||||
{ |
||||
int irn; |
||||
stringstream ss(command.c_str()); |
||||
ss >> irn; |
||||
if (irn >= 1 && irn <= 5) |
||||
{ |
||||
m_nlsr.getConfParameter().setInterestRetryNumber(irn); |
||||
|
||||
try { |
||||
std::string logLevel = SectionAttributeTree.get<string>("log-level"); |
||||
if ( boost::iequals(logLevel, "info") || boost::iequals(logLevel, "debug")) { |
||||
m_nlsr.getConfParameter().setLogLevel(logLevel); |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandInterestResendTime(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [interest-resend-time s]" << endl; |
||||
} |
||||
else |
||||
{ |
||||
int irt; |
||||
stringstream ss(command.c_str()); |
||||
ss >> irt; |
||||
if (irt >= 1 && irt <= 20) |
||||
{ |
||||
m_nlsr.getConfParameter().setInterestResendTime(irt); |
||||
else { |
||||
std::cerr << "Wrong value for log-level "; |
||||
std::cerr << "Allowed value: INFO, DEBUG" << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandLsaRefreshTime(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [interest-resend-time s]" << endl; |
||||
} |
||||
else |
||||
{ |
||||
int lrt; |
||||
stringstream ss(command.c_str()); |
||||
ss >> lrt; |
||||
if (lrt >= 240 && lrt <= 7200) |
||||
{ |
||||
m_nlsr.getConfParameter().setLsaRefreshTime(lrt); |
||||
} |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
return 0; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandMaxFacesPerPrefix(string command) |
||||
bool |
||||
ConfFileProcessor::processConfSectionNeighbors(boost::property_tree::ptree |
||||
SectionAttributeTree) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [max-faces-per-prefix n]" << endl; |
||||
} |
||||
else |
||||
{ |
||||
int mfpp; |
||||
stringstream ss(command.c_str()); |
||||
ss >> mfpp; |
||||
if (mfpp >= 0 && mfpp <= 60) |
||||
{ |
||||
m_nlsr.getConfParameter().setMaxFacesPerPrefix(mfpp); |
||||
try { |
||||
int retrials = SectionAttributeTree.get<int>("hello-retries"); |
||||
if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) { |
||||
m_nlsr.getConfParameter().setInterestRetryNumber(retrials); |
||||
} |
||||
else { |
||||
std::cerr << "Wrong value for hello-retries. "; |
||||
std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-"; |
||||
std::cerr << HELLO_RETRIES_MAX << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandTunnelType(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl; |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
else |
||||
{ |
||||
if (command == "tcp" || command == "TCP") |
||||
{ |
||||
m_nlsr.getConfParameter().setTunnelType(1); |
||||
try { |
||||
int timeOut = SectionAttributeTree.get<int>("hello-timeout"); |
||||
if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) { |
||||
m_nlsr.getConfParameter().setInterestResendTime(timeOut); |
||||
} |
||||
else if (command == "udp" || command == "UDP") |
||||
{ |
||||
m_nlsr.getConfParameter().setTunnelType(0); |
||||
} |
||||
else |
||||
{ |
||||
cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl; |
||||
else { |
||||
std::cerr << "Wrong value for hello-timeout. "; |
||||
std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-"; |
||||
std::cerr << HELLO_TIMEOUT_MAX << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandChronosyncSyncPrefix(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [chronosync-sync-prefix name/prefix]!" << endl; |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
} |
||||
else |
||||
{ |
||||
m_nlsr.getConfParameter().setChronosyncSyncPrefix(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandLogDir(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [log-dir /path/to/log/dir]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
m_nlsr.getConfParameter().setLogDir(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandCertDir(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [cert-dir /path/to/cert/dir]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
m_nlsr.getConfParameter().setCertDir(command); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandDebugging(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [debugging on/of]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
if (command == "on" || command == "ON") |
||||
{ |
||||
m_nlsr.getConfParameter().setDebugging(1); |
||||
try { |
||||
int interval = SectionAttributeTree.get<int>("hello-interval"); |
||||
if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) { |
||||
m_nlsr.getConfParameter().setInfoInterestInterval(interval); |
||||
} |
||||
else if (command == "off" || command == "off") |
||||
{ |
||||
m_nlsr.getConfParameter().setDebugging(0); |
||||
} |
||||
else |
||||
{ |
||||
cerr << " Wrong command format ! [debugging on/off]!" << endl; |
||||
else { |
||||
std::cerr << "Wrong value for hello-interval. "; |
||||
std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-"; |
||||
std::cerr << HELLO_INTERVAL_MAX << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandDetailedLogging(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [detailed-logging on/off]!" << endl; |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
} |
||||
else |
||||
{ |
||||
if (command == "on" || command == "ON") |
||||
for (boost::property_tree::ptree::const_iterator tn = |
||||
SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) { |
||||
|
||||
if (tn->first == "neighbor") |
||||
{ |
||||
m_nlsr.getConfParameter().setDetailedLogging(1); |
||||
} |
||||
else if (command == "off" || command == "off") |
||||
{ |
||||
m_nlsr.getConfParameter().setDetailedLogging(0); |
||||
} |
||||
else |
||||
{ |
||||
cerr << " Wrong command format ! [detailed-logging on/off]!" << endl; |
||||
try { |
||||
boost::property_tree::ptree CommandAttriTree = tn->second; |
||||
std::string name = CommandAttriTree.get<std::string>("name"); |
||||
std::string faceUri = CommandAttriTree.get<std::string>("face-uri"); |
||||
double linkCost = CommandAttriTree.get<double>("link-cost", |
||||
Adjacent::DEFAULT_LINK_COST); |
||||
ndn::Name neighborName(name); |
||||
if (!neighborName.empty()) { |
||||
Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0); |
||||
m_nlsr.getAdjacencyList().insert(adj); |
||||
} |
||||
else { |
||||
cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]"; |
||||
std::cerr << " or bad URI format" << std::endl; |
||||
} |
||||
} |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return 0; |
||||
return true; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandIsHyperbolicCalc(string command) |
||||
bool |
||||
ConfFileProcessor::processConfSectionHyperbolic(boost::property_tree::ptree |
||||
SectionAttributeTree) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
if (command == "on" || command == "ON") |
||||
{ |
||||
m_nlsr.getConfParameter().setIsHyperbolicCalc(1); |
||||
std::string state; |
||||
try { |
||||
state= SectionAttributeTree.get<string>("state","off"); |
||||
if (boost::iequals(state, "off")) { |
||||
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF); |
||||
} |
||||
else if (command == "dry-run" || command == "DRY-RUN") |
||||
{ |
||||
m_nlsr.getConfParameter().setIsHyperbolicCalc(2); |
||||
else if (boost::iequals(state, "on")) { |
||||
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
||||
} |
||||
else if (command == "off" || command == "off") |
||||
{ |
||||
m_nlsr.getConfParameter().setIsHyperbolicCalc(0); |
||||
else if (state == "dry-run") { |
||||
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
||||
} |
||||
else |
||||
{ |
||||
cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl; |
||||
else { |
||||
std::cerr << "Wrong format for hyperbolic state." << std::endl; |
||||
std::cerr << "Allowed value: off, on, dry-run" << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandHyperbolicCordinate(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [hyperbolic-cordinate r 0]!" << endl; |
||||
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0) |
||||
{ |
||||
return -1; |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
|
||||
try { |
||||
/* Radius and angle is mandatory configuration parameter in hyperbolic section.
|
||||
* Even if router can have hyperbolic routing calculation off but other router |
||||
* in the network may use hyperbolic routing calculation for FIB generation. |
||||
* So each router need to advertise its hyperbolic coordinates in the network |
||||
*/ |
||||
double radius = SectionAttributeTree.get<double>("radius"); |
||||
double angle = SectionAttributeTree.get<double>("angle"); |
||||
if (!m_nlsr.getConfParameter().setCorR(radius)) { |
||||
return false; |
||||
} |
||||
m_nlsr.getConfParameter().setCorTheta(angle); |
||||
} |
||||
else |
||||
{ |
||||
Tokenizer nt(command, " "); |
||||
stringstream ssr(nt.getFirstToken().c_str()); |
||||
stringstream sst(nt.getRestOfLine().c_str()); |
||||
double r, theta; |
||||
ssr >> r; |
||||
sst >> theta; |
||||
m_nlsr.getConfParameter().setCorR(r); |
||||
m_nlsr.getConfParameter().setCorTheta(theta); |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
if (state == "on" || state == "dry-run") { |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandNdnNeighbor(string command) |
||||
bool |
||||
ConfFileProcessor::processConfSectionFib(boost::property_tree::ptree |
||||
SectionAttributeTree) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
Tokenizer nt(command, " "); |
||||
if (nt.getRestOfLine().empty()) |
||||
try { |
||||
int maxFacesPerPrefixNumber = |
||||
SectionAttributeTree.get<int>("max-faces-per-prefix"); |
||||
if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN && |
||||
maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX) |
||||
{ |
||||
cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl; |
||||
return 0; |
||||
m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber); |
||||
} |
||||
else |
||||
{ |
||||
stringstream sst(nt.getRestOfLine().c_str()); |
||||
int faceId; |
||||
sst >> faceId; |
||||
Adjacent adj(nt.getFirstToken(), faceId, 10, 0, 0); |
||||
m_nlsr.getAdjacencyList().insert(adj); |
||||
else { |
||||
std::cerr << "Wrong value for max-faces-per-prefix. "; |
||||
std::cerr << "NLSR will user default value"; |
||||
std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandNdnName(string command) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [ndnname name/prefix]!" << endl; |
||||
} |
||||
else |
||||
{ |
||||
m_nlsr.getNamePrefixList().insert(command); |
||||
catch (const std::exception& ex) { |
||||
cerr << ex.what() << endl; |
||||
return false; |
||||
} |
||||
return 0; |
||||
return true; |
||||
} |
||||
|
||||
|
||||
int |
||||
ConfFileProcessor::processConfCommandLinkCost(string command) |
||||
bool |
||||
ConfFileProcessor::processConfSectionAdvertising(boost::property_tree::ptree |
||||
SectionAttributeTree) |
||||
{ |
||||
if (command.empty()) |
||||
{ |
||||
cerr << " Wrong command format ! [link-cost nbr/name cost]!" << endl; |
||||
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0) |
||||
{ |
||||
return -1; |
||||
for (boost::property_tree::ptree::const_iterator tn = |
||||
SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) { |
||||
if (tn->first == "prefix") { |
||||
try { |
||||
std::string prefix = tn->second.data(); |
||||
ndn::Name namePrefix(prefix); |
||||
if (!namePrefix.empty()) { |
||||
m_nlsr.getNamePrefixList().insert(namePrefix); |
||||
} |
||||
else { |
||||
std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI"; |
||||
std::cerr << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
catch (const std::exception& ex) { |
||||
std::cerr << ex.what() << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
Tokenizer nt(command, " "); |
||||
stringstream sst(nt.getRestOfLine().c_str()); |
||||
double cost; |
||||
sst >> cost; |
||||
m_nlsr.getAdjacencyList().updateAdjacentLinkCost(nt.getFirstToken(), cost); |
||||
} |
||||
return 0; |
||||
return true; |
||||
} |
||||
|
||||
} //namespace nlsr
|
||||
|
||||
}//namespace NLSR
|
||||
|
@ -1,31 +0,0 @@
|
||||
#include <iostream> |
||||
#include "conf-parameter.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
using namespace std; |
||||
|
||||
ostream& |
||||
operator<<(ostream& os, ConfParameter& cfp) |
||||
{ |
||||
os << "Router Name: " << cfp.getRouterName() << endl; |
||||
os << "Site Name: " << cfp.getSiteName() << endl; |
||||
os << "Network: " << cfp.getNetwork() << endl; |
||||
os << "Router Prefix: " << cfp.getRouterPrefix() << endl; |
||||
os << "ChronoSync sync Prifex: " << cfp.getChronosyncSyncPrefix() << endl; |
||||
os << "Interest Retry number: " << cfp.getInterestRetryNumber() << endl; |
||||
os << "Interest Resend second: " << cfp.getInterestResendTime() << endl; |
||||
os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << endl; |
||||
os << "LSA refresh time: " << cfp.getLsaRefreshTime() << endl; |
||||
os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << endl; |
||||
os << "Log Dir: " << cfp.getLogDir() << endl; |
||||
os << "Detalied logging: " << cfp.getDetailedLogging() << endl; |
||||
os << "Debugging: " << cfp.getDebugging() << endl; |
||||
os << "Hyperbolic ROuting: " << cfp.getIsHyperbolicCalc() << endl; |
||||
os << "Hyp R: " << cfp.getCorR() << endl; |
||||
os << "Hyp theta: " << cfp.getCorTheta() << endl; |
||||
os << "Tunnel Type: " << cfp.getTunnelType() << endl; |
||||
return os; |
||||
} |
||||
|
||||
} //namespace nlsr
|
@ -0,0 +1,115 @@
|
||||
#ifndef NLSR_FACE_MAP_HPP |
||||
#define NLSR_FACE_MAP_HPP |
||||
|
||||
namespace nlsr { |
||||
|
||||
class FaceMapEntry { |
||||
|
||||
public: |
||||
FaceMapEntry(const std::string& faceUri, uint32_t faceId) |
||||
: m_faceUri(faceUri) |
||||
, m_faceId(faceId) |
||||
{ |
||||
} |
||||
|
||||
void |
||||
setFaceUri(const std::string& faceUri) |
||||
{ |
||||
m_faceUri = faceUri; |
||||
} |
||||
|
||||
const std::string& |
||||
getFaceUri() const |
||||
{ |
||||
return m_faceUri; |
||||
} |
||||
|
||||
void |
||||
setFaceId(uint32_t faceId) |
||||
{ |
||||
m_faceId = faceId; |
||||
} |
||||
|
||||
uint32_t |
||||
getFaceId() const |
||||
{ |
||||
return m_faceId; |
||||
} |
||||
|
||||
bool |
||||
compare(const FaceMapEntry& fme) |
||||
{ |
||||
return m_faceUri == fme.getFaceUri(); |
||||
} |
||||
|
||||
private: |
||||
std::string m_faceUri; |
||||
uint32_t m_faceId; |
||||
}; |
||||
|
||||
inline std::ostream& |
||||
operator<<(std::ostream& os, const FaceMapEntry& fme) |
||||
{ |
||||
os << "Face Map Entry (FaceUri: " << fme.getFaceUri() << " Face Id: "; |
||||
os << fme.getFaceId() << ")" << std::endl; |
||||
return os; |
||||
} |
||||
|
||||
class FaceMap { |
||||
|
||||
public: |
||||
FaceMap() |
||||
{ |
||||
} |
||||
|
||||
~FaceMap() |
||||
{ |
||||
} |
||||
|
||||
inline void |
||||
update(const std::string& faceUri, uint32_t faceId) |
||||
{ |
||||
FaceMapEntry fme(faceUri, faceId); |
||||
std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(), |
||||
m_table.end(), |
||||
bind(&FaceMapEntry::compare, |
||||
&fme, _1)); |
||||
if (it == m_table.end()) { |
||||
m_table.push_back(fme); |
||||
} |
||||
else { |
||||
(*it).setFaceId(fme.getFaceId()); |
||||
} |
||||
} |
||||
|
||||
inline uint32_t |
||||
getFaceId(const std::string& faceUri) |
||||
{ |
||||
FaceMapEntry fme(faceUri, 0); |
||||
std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(), |
||||
m_table.end(), |
||||
bind(&FaceMapEntry::compare, |
||||
&fme, _1)); |
||||
if (it != m_table.end()) { |
||||
return (*it).getFaceId(); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
inline void |
||||
print() |
||||
{ |
||||
std::cout << "------- Face Map-----------" << std::endl; |
||||
for(std::list<FaceMapEntry>::iterator it = m_table.begin(); |
||||
it != m_table.end(); ++it) { |
||||
std::cout << (*it); |
||||
} |
||||
} |
||||
|
||||
private: |
||||
std::list<FaceMapEntry> m_table; |
||||
}; |
||||
|
||||
} //namespace nlsr
|
||||
|
||||
#endif //NLSR_FACE_MAP_HPP
|
@ -1,13 +0,0 @@
|
||||
#include "nexthop.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, NextHop& nh) |
||||
{ |
||||
os << "Face: " << nh.getConnectingFace() << " Route Cost: " << |
||||
nh.getRouteCost(); |
||||
return os; |
||||
} |
||||
|
||||
}//namespace nlsr
|
@ -1,111 +0,0 @@
|
||||
#include <iostream> |
||||
#include <boost/tokenizer.hpp> |
||||
#include <boost/algorithm/string.hpp> |
||||
#include <string> |
||||
#include <algorithm> |
||||
|
||||
#include <ndn-cxx/face.hpp> |
||||
|
||||
#include "tokenizer.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
using namespace std; |
||||
using namespace boost; |
||||
|
||||
void |
||||
Tokenizer::makeToken() |
||||
{ |
||||
char_separator<char> sep(m_seps.c_str()); |
||||
tokenizer<char_separator<char> >tokens(m_originalString, sep); |
||||
tokenizer<char_separator<char> >::iterator tok_iter = tokens.begin(); |
||||
for (; tok_iter != tokens.end(); ++tok_iter) |
||||
{ |
||||
string oneToken(*tok_iter); |
||||
trim(oneToken); |
||||
if (!oneToken.empty()) |
||||
{ |
||||
insertToken(oneToken); |
||||
} |
||||
} |
||||
m_firstToken = m_vTokenList[0]; |
||||
makeRestOfTheLine(); |
||||
} |
||||
|
||||
void |
||||
Tokenizer::insertToken(const string& token) |
||||
{ |
||||
m_tokenList.push_back(token); |
||||
m_vTokenList.push_back(token); |
||||
} |
||||
|
||||
uint32_t |
||||
Tokenizer::getTokenPosition(string& token) |
||||
{ |
||||
uint32_t pos = -1; |
||||
uint32_t i = 0; |
||||
for (std::list<string>::iterator it = m_tokenList.begin(); |
||||
it != m_tokenList.end(); it++) |
||||
{ |
||||
if ((*it) == token) |
||||
{ |
||||
break; |
||||
} |
||||
i++; |
||||
} |
||||
if (i < m_tokenList.size()) |
||||
{ |
||||
pos = i; |
||||
} |
||||
return pos; |
||||
} |
||||
|
||||
string |
||||
Tokenizer::getTokenString(uint32_t from , uint32_t to) |
||||
{ |
||||
string returnString = ""; |
||||
if ((to < m_tokenList.size()) && |
||||
(to >= from && to < m_tokenList.size())) |
||||
{ |
||||
for (uint32_t i = from; i <= to; i++) |
||||
{ |
||||
returnString += m_seps; |
||||
returnString += m_vTokenList[i]; |
||||
} |
||||
} |
||||
trim(returnString); |
||||
return returnString; |
||||
} |
||||
|
||||
string |
||||
Tokenizer::getTokenString(uint32_t from) |
||||
{ |
||||
return getTokenString(from, m_tokenList.size() - 1); |
||||
} |
||||
|
||||
static bool |
||||
tokenCompare(string& s1, string& s2) |
||||
{ |
||||
return s1 == s2; |
||||
} |
||||
|
||||
void |
||||
Tokenizer::makeRestOfTheLine() |
||||
{ |
||||
m_restOfTheLine = getTokenString(1); |
||||
} |
||||
|
||||
bool |
||||
Tokenizer::doesTokenExist(string token) |
||||
{ |
||||
std::list<string>::iterator it = std::find_if(m_tokenList.begin(), |
||||
m_tokenList.end(), |
||||
ndn::bind(&tokenCompare, _1 , token)); |
||||
if (it != m_tokenList.end()) |
||||
{ |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
}//namespace nlsr
|
@ -1,117 +0,0 @@
|
||||
#ifndef NLSR_TOKENIZER_HPP |
||||
#define NLSR_TOKENIZER_HPP |
||||
|
||||
#include <iostream> |
||||
#include <boost/tokenizer.hpp> |
||||
#include <boost/algorithm/string.hpp> |
||||
#include <string> |
||||
#include <list> |
||||
#include <vector> |
||||
|
||||
namespace nlsr { |
||||
|
||||
class Tokenizer |
||||
{ |
||||
public: |
||||
Tokenizer(const std::string& inputString) |
||||
: m_firstToken() |
||||
, m_restOfTheLine() |
||||
, m_currentPosition(0) |
||||
{ |
||||
m_seps = " "; |
||||
m_originalString = inputString; |
||||
makeToken(); |
||||
} |
||||
|
||||
Tokenizer(const std::string& inputString, const std::string& separator) |
||||
: m_firstToken() |
||||
, m_restOfTheLine() |
||||
, m_currentPosition(0) |
||||
{ |
||||
m_seps = separator; |
||||
m_originalString = inputString; |
||||
makeToken(); |
||||
} |
||||
|
||||
std::string |
||||
getFirstToken() |
||||
{ |
||||
return m_firstToken; |
||||
} |
||||
|
||||
std::string |
||||
getRestOfLine() |
||||
{ |
||||
return m_restOfTheLine; |
||||
} |
||||
|
||||
void |
||||
resetCurrentPosition(uint32_t cp = 0) |
||||
{ |
||||
if (cp <= m_vTokenList.size()) |
||||
{ |
||||
m_currentPosition = cp; |
||||
} |
||||
} |
||||
|
||||
std::string |
||||
getNextToken() |
||||
{ |
||||
if (m_currentPosition <= (m_vTokenList.size() - 1)) |
||||
{ |
||||
return m_vTokenList[m_currentPosition++]; |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
uint32_t |
||||
getTokenNumber() |
||||
{ |
||||
return m_tokenList.size(); |
||||
} |
||||
|
||||
std::string |
||||
getToken(unsigned int position) |
||||
{ |
||||
if (position < m_vTokenList.size()) |
||||
{ |
||||
return m_vTokenList[position]; |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
uint32_t |
||||
getTokenPosition(std::string& token); |
||||
|
||||
std::string |
||||
getTokenString(uint32_t from , uint32_t to); |
||||
|
||||
std::string |
||||
getTokenString(uint32_t from); |
||||
|
||||
bool |
||||
doesTokenExist(std::string token); |
||||
|
||||
|
||||
private: |
||||
|
||||
void |
||||
makeToken(); |
||||
|
||||
void |
||||
insertToken(const std::string& token); |
||||
|
||||
void |
||||
makeRestOfTheLine(); |
||||
|
||||
std::string m_seps; |
||||
std::string m_originalString; |
||||
std::string m_firstToken; |
||||
std::string m_restOfTheLine; |
||||
std::list<std::string> m_tokenList; |
||||
std::vector<std::string> m_vTokenList; |
||||
uint32_t m_currentPosition; |
||||
}; |
||||
|
||||
}//namespace nlsr
|
||||
#endif //NLSR_TOKENIZER_HPP
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Regents of the University of Memphis. |
||||
* See COPYING for copyright and distribution information. |
||||
*/ |
||||
|
||||
#include "utility/tokenizer.hpp" |
||||
#include <boost/test/unit_test.hpp> |
||||
|
||||
namespace nlsr { |
||||
|
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestTokenizer) |
||||
|
||||
BOOST_AUTO_TEST_CASE(TokenizerBasic) |
||||
{ |
||||
Tokenizer token1("/ndn/memphis.edu/cs", "/"); |
||||
Tokenizer token2("/ndn/memphis.edu/cs", "/"); |
||||
|
||||
Tokenizer token3("/test/hello"); |
||||
|
||||
BOOST_CHECK(token1.getFirstToken() == token2.getFirstToken()); |
||||
|
||||
BOOST_CHECK_EQUAL(token1.getRestOfLine(), token2.getRestOfLine()); |
||||
|
||||
BOOST_CHECK(token1.getFirstToken() != token3.getFirstToken()); |
||||
|
||||
BOOST_CHECK(token1.getRestOfLine() != token3.getRestOfLine()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} //namespace test
|
||||
} //namespace nlsr
|
Loading…
Reference in new issue