29 Commits
Author SHA1 Message Date
Muktadir R Chowdhury 800833b7ac docs+build+boilerplate: Prepare release of version 0.3.0
Change-Id: I60f359e73b049d844470670a0088a00522f7564e
2016-08-01 13:33:53 -05:00
Nick Gordon e8e03ac303 communication+route: Do not advertise Adjacency LSAs when hyperbolic routing is enabled
refs: #2402

Change-Id: If204807733f858606e31a0ff8231f140905063cf
2016-07-29 12:43:46 -07:00
Alexander Afanasyev 5ec9ae4271 ci: Update Travis CI script to build using Ubuntu 14.04 and OS X 10.9
Change-Id: Ib73bf5a5727c1d9b58a0f2a2fde66249cbc19e3d
2016-07-29 10:32:57 -07:00
Vince Lehman f7eec4f4c0 Make LSA buildable when one node is ACTIVE
refs: #2802

Change-Id: If3f99895522e22103130f32bb6634bf9a5691fe7
2016-07-28 12:41:43 -07:00
Nick Gordon 5c467f0ca8 Do not distribute coordinate LSAs when using link-state routing.
refs: #3661

Change-Id: I6a1467225def5ba04e2179480503cfe01968cede
2016-07-28 12:28:41 -05:00
Muktadir R Chowdhury aa3b085384 lsdb: Segment LSAs larger than max segment size
refs: #2965

Change-Id: I5dd091b663db2cc5e2d925144e57ee55a486b3cd
2016-07-26 12:27:55 -05:00
Ashlesh Gawande d02c3880d5 lsa: Accept LSA type argument in LSA base constructor
refs: #2788

Change-Id: I12d9b26fb9087b037134988f1594576ed7ba90f3
2016-07-25 18:28:39 -05:00
Muktadir R Chowdhury 3ac0728e5a publisher: set router-name command prefix correctly
refs: #3651

Change-Id: Ic3771de5161fc482f76df78035dcb9f5325e1a9d
2016-07-21 10:24:15 -05:00
Junxiao Shi c778e814db tests: don't use DummyClientFace::sentDatas
refs #3383

Change-Id: I7cbe7d147de0b0066ee0ab4c25f2ec707a081f79
2016-07-14 15:44:26 +00:00
Vince Lehman af909fcc13 build: Don't install unit tests; use brew version of openssl on OS X Jenkins
refs: #3359

Change-Id: I0b51ede8be0abafe4cbbe39274b291d3c8549872
2016-01-14 10:33:22 -06:00
Muktadir R Chowdhury c69da0a350 tests: Use ndn-cxx/DummyClientFace
refs: #2637

Change-Id: Ife16a81d08e538b4b0a82f1f5d4cc819fc764257
2016-01-11 12:05:24 -06:00
Vince Lehman 0ff5d45ba8 docs: Prepare version 0.2.2 release notes
Change-Id: I72a1847e7c20d9bac3d85b2263b974ddbcee3431
2016-01-04 17:23:06 -06:00
Ashlesh Gawande 5d9c0573c0 security: Remove unused disabled files
Change-Id: Ifbbe284f5e3586e6256ffa30902926c2d751743e
refs: #2960
2015-12-21 15:45:50 -06:00
Muktadir R Chowdhury 4c7caadb72 nlsrc: adapt to ndn-cxx SegmentFetcher API change
Refs: #2734
Change-Id: I76f1f1a6b95d2df18a8deef545be5027ad6bbc7c
2015-12-04 13:25:43 -08:00
Alexander Afanasyev f9f3910dd2 build+nsync+tests+docs: Fix compilation for boost 1.59, doxygen docs, and other fixes
Requires ndn-cxx:commit:e3e2505aa03e0b298e1a8dfc9876f1f8dafcaaba (ndn-cxx-0.4.0-beta2-11-ge3e2505)
or earlier commit.

Change-Id: I6ad359aa368b3346464f2aa74a1ab319fcd3ab7a
2015-12-04 13:25:28 -08:00
Vince Lehman 53c0e3e9ee Use MulticastStrategy instead of deprecated BroadcastStrategy
refs: #3011

Change-Id: I7c32cf13945853fe76008271a77878d2bf6e9215
2015-09-14 14:36:49 -05:00
Vince Lehman c57c64b633 Refactor initialization of NLSR instance
refs: #3091

Change-Id: I07108015dc0704e85f5c37b91b53838d7b0f41d0
2015-08-11 11:55:29 -05:00
Joao Pereira 97473d47fd nlsr: avoid deprecated prefix registration APIs
refs #2932

Change-Id: Id874d40d3b6209bedc6f92a44b5c49eb9ed31efe
2015-07-06 15:38:23 -04:00
Vince Lehman 5363c7946b docs: Prepare version 0.2.1 release notes
Change-Id: Ibde6faea916ca90f3c11b7d1189c7044ca9bc5ec
2015-06-30 06:51:31 -07:00
Vince Lehman f4772d4f21 Fix compilation after namespace change in ndn-cxx
refs: #2951

Change-Id: Ia9f3caee4733e7f137b5f6f22f7e154069b37f69
2015-06-29 15:06:29 -05:00
alvy 46ccaae829 tests: Remove FaceDestroyEvent test's reliance on nlsrSeqNo.txt
refs: #2881

Change-Id: I32d329d058e9715ca5cdca74867b6588775e93ff
2015-06-26 11:28:20 -05:00
alvy c69c9af931 tests: Check ACTIVE/INACTIVE Adjacencies in LSA construction
refs #2735

Change-Id: I5d0c4940c0bc688a895a71603c9ea93b87cfba42
2015-06-26 10:49:01 -05:00
Vince Lehman d33e5bc475 update: Disable PrefixUpdateProcessor when validator is not in config
refs: 2814

Change-Id: I2669dcd4af36ebe09f3e20189a99c812e0e6ad7b
2015-06-24 11:33:57 -07:00
alvy dce3f18229 src: Fix non-incrementing Adjacency number in AdjLsa::writeLog
refs #2594

Change-Id: I64ae57060ffb95c92e86da356eb6ba80f1d77f06
2015-06-24 10:54:43 -05:00
Vince Lehman cae33b69f2 route: Prevent incomplete removal of NPT entry
refs: #2785

Change-Id: Ic8ff955236784db76c55b94bf9300fb21ea9beae
2015-06-08 11:59:47 -05:00
Vince Lehman 18df0602d3 docs: Change toctree order
Change-Id: I121f41b54afc10225f90ebb0a98ad4e444058bfe
2015-05-13 14:32:29 -07:00
Vince Lehman 41b173ed54 route: Correct bidirectional links with differing costs
refs: #2801

Change-Id: Iacabcb5484f4ccab6c74700dd8ebcf7b1ad99917
2015-05-11 10:11:22 -05:00
Vince Lehman 9630fbf4e0 route: Fix component appending in NamePrefixTable::removeEntry
refs: #2322

Change-Id: I511414be322dccc713d3eaef737edd87a51e8b51
2015-05-09 11:13:42 -07:00
Alexander Afanasyev a6f3e645f5 build: Update waf to version 1.8.9 (with custom patches)
https://github.com/cawka/waf/tree/2a098b1e9bc626c19cbd47c1f670758c17edf54c

Change-Id: Ibacc49368d81e1d2b9059b8153a86bcfc026a295
Refs: #2792
2015-05-06 14:52:35 -07:00
113 changed files with 2407 additions and 2256 deletions

No files matched your search

+1
View File
@@ -10,6 +10,7 @@ if has OSX $NODE_LABELS && ! has OSX-10.8-c++11-64bit $NODE_LABELS; then
brew update
brew upgrade
brew install boost pkg-config sqlite cryptopp log4cxx protobuf openssl
brew link --force openssl log4cxx protobuf
brew cleanup
fi
+12 -1
View File
@@ -2,12 +2,17 @@
set -x
set -e
JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$JDIR"/util.sh
pushd /tmp >/dev/null
INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
sudo rm -Rf ndn-cxx-latest
git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
@@ -23,9 +28,15 @@ sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
pushd ndn-cxx >/dev/null
./waf configure -j1 --color=yes --without-osx-keychain
./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain
./waf -j1 --color=yes
sudo ./waf install -j1 --color=yes
popd >/dev/null
popd >/dev/null
if has Linux $NODE_LABELS; then
sudo ldconfig
elif has FreeBSD $NODE_LABELS; then
sudo ldconfig -a
fi
+18 -9
View File
@@ -1,15 +1,24 @@
sudo: true
language: cpp
os:
- linux
compiler:
- gcc
sudo: required
language: generic
matrix:
include:
- os: linux
dist: trusty
env:
- CXX=g++
- NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
- os: linux
dist: trusty
env:
- CXX=clang++
- NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
- os: osx
env:
- CXX=clang++
- NODE_LABELS="OSX OSX-10.9"
notifications:
email:
on_success: always
on_failure: always
env:
global:
- NODE_LABELS="Linux Ubuntu Ubuntu-12.04 Ubuntu-12.04-64bit Boost1.48"
script:
- ./.jenkins
+146 -28
View File
@@ -1,53 +1,58 @@
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
from waflib import Logs, Configure
from waflib import Logs, Configure, Utils
def options(opt):
opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
def configure(conf):
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
defaultFlags = ['-std=c++0x', '-std=c++11',
'-stdlib=libc++', # clang on OSX < 10.9 by default uses a non
# C++11-compatible STL library
'-Wall', '-Wno-long-long']
cxx = conf.env['CXX_NAME'] # CXX_NAME represents generic name of the compiler
if cxx == 'gcc':
flags = GccFlags()
elif cxx == 'clang':
flags = ClangFlags()
else:
flags = CompilerFlags()
Logs.warn('The code has not yet been tested with %s compiler' % cxx)
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
# General flags are always applied (e.g., selecting C++11 mode)
generalFlags = flags.getGeneralFlags(conf)
conf.add_supported_cxxflags(generalFlags['CXXFLAGS'])
conf.add_supported_linkflags(generalFlags['LINKFLAGS'])
conf.env.DEFINES += generalFlags['DEFINES']
# Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
# corresponding environment variables are not set.
# DEFINES are always applied.
if conf.options.debug:
conf.define('_DEBUG', 1)
defaultFlags += ['-O0',
'-Og', # gcc >= 4.8
'-g3',
'-fcolor-diagnostics', # clang
'-fdiagnostics-color', # gcc >= 4.9
'-Werror',
'-Wno-error=deprecated-register',
'-Wno-error=maybe-uninitialized', # Bug #1615
'-Wno-error=unneeded-internal-declaration', # Bug #1588
'-Wno-nested-anon-types',
]
extraFlags = flags.getDebugFlags(conf)
if areCustomCxxflagsPresent:
missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS]
if len(missingFlags) > 0:
Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
% " ".join(conf.env.CXXFLAGS))
Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
else:
conf.add_supported_cxxflags(defaultFlags)
else:
defaultFlags += ['-O2', '-g']
if not areCustomCxxflagsPresent:
conf.add_supported_cxxflags(defaultFlags)
extraFlags = flags.getOptimizedFlags(conf)
# clang on OSX < 10.9 by default uses a non C++11-compatible STL library
conf.add_supported_linkflags(['-stdlib=libc++'])
if not areCustomCxxflagsPresent:
conf.add_supported_cxxflags(extraFlags['CXXFLAGS'])
conf.add_supported_linkflags(extraFlags['LINKFLAGS'])
conf.env.DEFINES += extraFlags['DEFINES']
@Configure.conf
def add_supported_cxxflags(self, cxxflags):
"""
Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
"""
self.start_msg('Checking allowed compile-stage flags for c++ compiler')
if len(cxxflags) == 0:
return
self.start_msg('Checking supported CXXFLAGS')
supportedFlags = []
for flag in cxxflags:
@@ -62,7 +67,10 @@ def add_supported_linkflags(self, linkflags):
"""
Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
"""
self.start_msg('Checking allowed link-stage flags for c++ compiler')
if len(linkflags) == 0:
return
self.start_msg('Checking supported LINKFLAGS')
supportedFlags = []
for flag in linkflags:
@@ -71,3 +79,113 @@ def add_supported_linkflags(self, linkflags):
self.end_msg(' '.join(supportedFlags))
self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS
class CompilerFlags(object):
def getGeneralFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
def getDebugFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['_DEBUG']}
def getOptimizedFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']}
class GccBasicFlags(CompilerFlags):
"""
This class defines basic flags that work for both gcc and clang compilers
"""
def getDebugFlags(self, conf):
flags = super(GccBasicFlags, self).getDebugFlags(conf)
flags['CXXFLAGS'] += ['-O0',
'-g3',
'-pedantic',
'-Wall',
'-Wextra',
'-Werror',
'-Wno-unused-parameter',
'-Wno-error=maybe-uninitialized', # Bug #1615
]
return flags
def getOptimizedFlags(self, conf):
flags = super(GccBasicFlags, self).getOptimizedFlags(conf)
flags['CXXFLAGS'] += ['-O2',
'-g',
'-pedantic',
'-Wall',
'-Wextra',
'-Wno-unused-parameter',
]
return flags
class GccFlags(GccBasicFlags):
def getGeneralFlags(self, conf):
flags = super(GccFlags, self).getGeneralFlags(conf)
version = tuple(int(i) for i in conf.env['CC_VERSION'])
if version < (4, 6, 0):
conf.fatal('The version of gcc you are using (%s) is too old.\n' %
'.'.join(conf.env['CC_VERSION']) +
'The minimum supported gcc version is 4.6.0.')
elif version < (4, 7, 0):
flags['CXXFLAGS'] += ['-std=c++0x']
else:
flags['CXXFLAGS'] += ['-std=c++11']
if version < (4, 8, 0):
flags['DEFINES'] += ['_GLIBCXX_USE_NANOSLEEP'] # Bug #2499
return flags
def getDebugFlags(self, conf):
flags = super(GccFlags, self).getDebugFlags(conf)
version = tuple(int(i) for i in conf.env['CC_VERSION'])
if version < (5, 1, 0):
flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
flags['CXXFLAGS'] += ['-Og', # gcc >= 4.8
'-fdiagnostics-color', # gcc >= 4.9
]
return flags
def getOptimizedFlags(self, conf):
flags = super(GccFlags, self).getOptimizedFlags(conf)
version = tuple(int(i) for i in conf.env['CC_VERSION'])
if version < (5, 1, 0):
flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
return flags
class ClangFlags(GccBasicFlags):
def getGeneralFlags(self, conf):
flags = super(ClangFlags, self).getGeneralFlags(conf)
flags['CXXFLAGS'] += ['-std=c++11']
if Utils.unversioned_sys_platform() == 'darwin':
flags['CXXFLAGS'] += ['-stdlib=libc++']
flags['LINKFLAGS'] += ['-stdlib=libc++']
return flags
def getDebugFlags(self, conf):
flags = super(ClangFlags, self).getDebugFlags(conf)
flags['CXXFLAGS'] += ['-fcolor-diagnostics',
'-Wno-unused-local-typedef', # Bugs #2657 and #3209
'-Wno-error=unneeded-internal-declaration', # Bug #1588
'-Wno-error=deprecated-register',
'-Wno-error=keyword-macro', # Bug #3235
'-Wno-nested-anon-types',
'-Wno-sign-compare',
'-Wno-keyword-macro',
'-Wno-error=ignored-qualifiers',
'-Wno-error=infinite-recursion',
]
return flags
def getOptimizedFlags(self, conf):
flags = super(ClangFlags, self).getOptimizedFlags(conf)
flags['CXXFLAGS'] += ['-fcolor-diagnostics',
'-Wno-unused-local-typedef', # Bugs #2657 and #3209
'-Wno-nested-anon-types',
'-Wno-sign-compare',
'-Wno-keyword-macro',
]
return flags
+8 -3
View File
@@ -28,6 +28,8 @@ NLSR is an open source project includes contributions from the members of the
* Minsheng Zhang <mzhang4@memphis.edu>
* Syed Obaid Amin <http://obaidamin.weebly.com/>
* Vince Lehman <http://vslehman.com>
* Muktadir R Chowdhury <mrchwdhr@memphis.edu>
* Nicholas Gordon <nmgordon@memphis.edu>
* University of California, Los Angeles
@@ -36,9 +38,12 @@ NLSR is an open source project includes contributions from the members of the
* Spyridon Mastorakis <http://cs.ucla.edu/~mastorakis/>
* Jiewen Tan <alanwake@ucla.edu>
* University of Arizona
* Junxiao Shi <https://www.cs.arizona.edu/people/shijunxiao/>
## Queries about NLSR
Any general question related to NLSR should be directed to Vince Lehman
(vslehman@memphis.edu) and security related question should be directed to
Yingdi Yu (yingdi@cs.ucla.edu)
Any question related to NLSR should be directed to Ashlesh Gawande (agawande@memphis.edu),
Muktadir R Chowdhury (mrchwdhr@memphis.edu), and Nicholas Gordon (nmgordon@memphis.edu).
+56
View File
@@ -1,6 +1,62 @@
Release Notes
=============
NLSR version 0.3.0 (changes since version 0.2.2)
++++++++++++++++++++++++++++++++++++++++++++++++
Release date: August 1, 2016
**Code changes**:
- Do not advertise Adjacency LSAs when hyperbolic routing is enabled (:issue:`2402`)
- Do not distribute coordinate LSAs when using link-state routing. (:issue:`3661`)
- LSAs should be segmented before they are published (:issue:`2965`)
- Don't use DummyClientFace::sentDatas (:issue:`3383`)
- Remove disabled security files (:issue:`2960`)
- Lsa type should be argument for base class LSA constructor (:issue:`2788`)
- Use ndn-cxx/DummyClientFace (:issue:`2637`)
**Bug fixes**:
- Unit tests cases are installed with `./waf install` (:issue:`3359`)
NLSR version 0.2.2 (changes since version 0.2.1)
++++++++++++++++++++++++++++++++++++++++++++++++
Release date: January 5, 2016
**Code changes**:
- Adapt code to changes in NFD/ndn-cxx version 0.4.0 release
NLSR version 0.2.1 (changes since version 0.2.0)
++++++++++++++++++++++++++++++++++++++++++++++++
Release date: June 30, 2015
**Code changes**:
- Using a configuration file without ``prefix-update-validator`` disables runtime advertise/withdraw instead of exiting (:issue:`2814`)
**Bug fixes**:
- Prevent incomplete removal of NPT entry (:issue:`2785`)
- Correct bidirectional links with differing costs (:issue:`2801`)
- Fix non-incrementing Adjacency number in AdjLsa::writeLog (:issue:`2594`)
- Remove FaceDestroyEvent test's reliance on nlsrSeqNo.txt (:issue:`2881`)
- Test ACTIVE/INACTIVE Adjacencies in LSA construction (:issue:`2735`)
NLSR version 0.2.0 (changes since version 0.1.0)
++++++++++++++++++++++++++++++++++++++++++++++++
+12
View File
@@ -87,6 +87,7 @@ configuration commands follows:
log-level INFO ; default value INFO, valid value DEBUG, INFO
log-dir /var/log/nlsr/
seq-dir /var/lib/nlsr/
; log4cxx-conf /path/to/log4cxx-conf
}
; the neighbors section contains the configuration for router's neighbors and hello's behavior
@@ -104,6 +105,17 @@ configuration commands follows:
hello-interval 60 ; interest sending interval in seconds. Default value 60
; valid values 30-90
; adj-lsa-build-interval is the time to wait in seconds after an Adjacency LSA build is scheduled
; before actually building the Adjacency LSA
adj-lsa-build-interval 5 ; default value 5. Valid values 0-5. It is recommended that
; adj-lsa-build-interval have a lower value than routing-calc-interval
; first-hello-interval is the time to wait in seconds before sending the first Hello Interest
first-hello-interval 10 ; Default value 10. Valid values 0-10
; neighbor command is used to configure router's neighbor. Each neighbor will need
; one block of neighbor command
+12 -13
View File
@@ -1782,18 +1782,6 @@ GENERATE_XML = NO
XML_OUTPUT = xml
# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a
# validating XML parser to check the syntax of the XML files.
# This tag requires that the tag GENERATE_XML is set to YES.
XML_SCHEMA =
# The XML_DTD tag can be used to specify a XML DTD, which can be used by a
# validating XML parser to check the syntax of the XML files.
# This tag requires that the tag GENERATE_XML is set to YES.
XML_DTD =
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
# listings (including syntax highlighting and cross-referencing information) to
# the XML output. Note that enabling this will significantly increase the size
@@ -1928,7 +1916,18 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED =
PREDEFINED = DOXYGEN=1 \
INIT_LOGGER(x)= \
BOOST_STATIC_ASSERT(x)= \
BOOST_CONCEPT_ASSERT(x)= \
BOOST_CONCEPT_REQUIRES(x)= \
DECL_OVERRIDE=override \
PUBLIC_WITH_TESTS_ELSE_PRIVATE=private \
PUBLIC_WITH_TESTS_ELSE_PROTECTED=protected \
PROTECTED_WITH_TESTS_ELSE_PRIVATE=private \
VIRTUAL_WITH_TESTS \
DECL_CLASS_FINAL=final \
DECL_FINAL=final
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
+2 -2
View File
@@ -30,14 +30,14 @@ NLSR Documentation
:maxdepth: 3
RELEASE-NOTES
INSTALL
GETTING-STARTED
INSTALL
ROUTER-CONFIG
SECURITY-CONFIG
manpages
- :doc:`INSTALL`
- :doc:`GETTING-STARTED`
- :doc:`INSTALL`
- :doc:`ROUTER-CONFIG`
- :doc:`SECURITY-CONFIG`
- :doc:`RELEASE-NOTES`
+2 -1
View File
@@ -187,7 +187,8 @@ security
k-regex ^([^<KEY><NLSR>]*)<NLSR><KEY><ksk-.*><ID-CERT>$
k-expand \\1
h-relation equal
p-regex ^([^<NLSR><LSA>]*)<NLSR><LSA>(<>*)<><><>$
; the last four components in the prefix should be <lsaType><seqNo><version><segmentNo>
p-regex ^([^<NLSR><LSA>]*)<NLSR><LSA>(<>*)<><><><>$
p-expand \\1\\2
}
}
+1 -1
View File
@@ -28,7 +28,7 @@
#include <log4cxx/logger.h>
#define INIT_LOGGER(name) \
static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name)
#define _LOG_DEBUG(x) \
LOG4CXX_DEBUG(staticModuleLogger, x);
+1
View File
@@ -29,6 +29,7 @@
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
#include <vector>
using namespace std;
+2
View File
@@ -20,7 +20,9 @@
#include "sync-socket.h"
#include "sync-logging.h"
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
using namespace std;
+19 -20
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,19 +17,16 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#include <algorithm>
#include <ndn-cxx/common.hpp>
#include "adjacency-list.hpp"
#include "adjacent.hpp"
#include "common.hpp"
#include "nlsr.hpp"
#include "logger.hpp"
#include <algorithm>
namespace nlsr {
INIT_LOGGER("AdjacencyList");
@@ -197,25 +195,26 @@ AdjacencyList::getAdjList()
}
bool
AdjacencyList::isAdjLsaBuildable(Nlsr& pnlsr)
AdjacencyList::isAdjLsaBuildable(const uint32_t interestRetryNo) const
{
uint32_t nbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end() ; it++) {
uint32_t nTimedOutNeighbors = 0;
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
nbrCount++;
for (const Adjacent& adjacency : m_adjList) {
if (adjacency.getStatus() == Adjacent::STATUS_ACTIVE) {
return true;
}
else {
if ((*it).getInterestTimedOutNo() >=
pnlsr.getConfParameter().getInterestRetryNumber()) {
nbrCount++;
}
else if (adjacency.getInterestTimedOutNo() >= interestRetryNo) {
nTimedOutNeighbors++;
}
}
if (nbrCount == m_adjList.size()) {
if (nTimedOutNeighbors == m_adjList.size()) {
return true;
}
return false;
else {
return false;
}
}
int32_t
+22 -9
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,10 +17,8 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#ifndef NLSR_ADJACENCY_LIST_HPP
#define NLSR_ADJACENCY_LIST_HPP
@@ -30,12 +29,13 @@
#include "adjacent.hpp"
namespace nlsr {
class Nlsr;
class AdjacencyList
{
public:
typedef std::list<Adjacent>::const_iterator const_iterator;
typedef std::list<Adjacent>::iterator iterator;
AdjacencyList();
~AdjacencyList();
@@ -73,7 +73,7 @@ public:
addAdjacents(AdjacencyList& adl);
bool
isAdjLsaBuildable(Nlsr& pnlsr);
isAdjLsaBuildable(const uint32_t interestRetryNo) const;
int32_t
getNumOfActiveNeighbor();
@@ -110,8 +110,21 @@ public:
void
writeLog();
public:
const_iterator
begin() const
{
return m_adjList.begin();
}
const_iterator
end() const
{
return m_adjList.end();
}
private:
std::list<Adjacent>::iterator
iterator
find(const ndn::Name& adjName);
private:
+20 -12
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -201,8 +201,7 @@ SyncLogicHandler::processUpdateFromSync(const SyncUpdate& update)
update.getSequencingManager().writeLog();
try {
if (isLsaNew(originRouter, NameLsa::TYPE_STRING, update.getNameLsaSeqNo())) {
if (isLsaNew(originRouter, NameLsa::TYPE_STRING, update.getNameLsaSeqNo())) {
_LOG_DEBUG("Received sync update with higher Name LSA sequence number than entry in LSDB");
expressInterestForLsa(update, NameLsa::TYPE_STRING, update.getNameLsaSeqNo());
@@ -210,20 +209,29 @@ SyncLogicHandler::processUpdateFromSync(const SyncUpdate& update)
if (isLsaNew(originRouter, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo())) {
_LOG_DEBUG("Received sync update with higher Adj LSA sequence number than entry in LSDB");
expressInterestForLsa(update, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo());
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
if (update.getAdjLsaSeqNo() != 0) {
_LOG_ERROR("Tried to fetch an adjacency LSA when hyperbolic routing"
<< " is enabled.");
}
}
else {
expressInterestForLsa(update, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo());
}
}
if (isLsaNew(originRouter, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo())) {
_LOG_DEBUG("Received sync update with higher Cor LSA sequence number than entry in LSDB");
expressInterestForLsa(update, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo());
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
if (update.getCorLsaSeqNo() != 0) {
_LOG_ERROR("Tried to fetch a coordinate LSA when link-state"
<< " is enabled.");
}
}
else {
expressInterestForLsa(update, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo());
}
}
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return;
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+22 -28
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -612,46 +612,40 @@ ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
{
ConfigSection::const_iterator it = section.begin();
if (it == section.end() || it->first != "validator")
{
std::cerr << "Error: Expect validator section!" << std::endl;
return false;
}
if (it == section.end() || it->first != "validator") {
std::cerr << "Error: Expect validator section!" << std::endl;
return false;
}
m_nlsr.loadValidator(it->second, m_confFileName);
it++;
if (it != section.end() && it->first == "prefix-update-validator") {
m_nlsr.getPrefixUpdateProcessor().enable();
m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
if (it == section.end() || it->first != "prefix-update-validator")
{
std::cerr << "Error: Expect prefix-update-validator section" << std::endl;
return false;
}
m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
it++;
for (; it != section.end(); it++)
{
it++;
for (; it != section.end(); it++) {
using namespace boost::filesystem;
if (it->first != "cert-to-publish")
{
std::cerr << "Error: Expect cert-to-publish!" << std::endl;
return false;
}
if (it->first != "cert-to-publish") {
std::cerr << "Error: Expect cert-to-publish!" << std::endl;
return false;
}
std::string file = it->second.data();
path certfilePath = absolute(file, path(m_confFileName).parent_path());
ndn::shared_ptr<ndn::IdentityCertificate> idCert =
shared_ptr<ndn::IdentityCertificate> idCert =
ndn::io::load<ndn::IdentityCertificate>(certfilePath.string());
if (!static_cast<bool>(idCert))
{
std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
return false;
}
if (idCert == nullptr) {
std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
return false;
}
m_nlsr.loadCertToPublish(idCert);
}
}
return true;
}
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -86,7 +86,7 @@ enum {
MAX_FACES_PER_PREFIX_MAX = 60
};
enum {
enum HyperbolicState {
HYPERBOLIC_STATE_OFF = 0,
HYPERBOLIC_STATE_ON = 1,
HYPERBOLIC_STATE_DRY_RUN = 2,
+5 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -22,7 +22,8 @@
#ifndef NLSR_HELLO_PROTOCOL_HPP
#define NLSR_HELLO_PROTOCOL_HPP
#include <boost/cstdint.hpp>
#include "test-access-control.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/management/nfd-control-parameters.hpp>
#include <ndn-cxx/util/scheduler.hpp>
@@ -59,9 +60,11 @@ private:
void
onContent(const ndn::Interest& interest, const ndn::Data& data);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
void
onContentValidated(const ndn::shared_ptr<const ndn::Data>& data);
private:
void
onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& msg);
+48 -28
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -53,12 +53,12 @@ NameLsa::getKey() const
return key;
}
NameLsa::NameLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
NameLsa::NameLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
NamePrefixList& npl)
: Lsa(NameLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsType = lst;
m_lsSeqNo = lsn;
m_expirationTimePoint = lt;
std::list<ndn::Name>& nl = npl.getNameList();
@@ -97,12 +97,16 @@ NameLsa::initializeFromContent(const std::string& content)
return false;
}
try {
m_lsType = *tok_iter++;
if (*tok_iter++ != NameLsa::TYPE_STRING) {
return false;
}
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++);
numName = boost::lexical_cast<uint32_t>(*tok_iter++);
}
catch (std::exception& e) {
_LOG_ERROR(e.what());
return false;
}
for (uint32_t i = 0; i < numName; i++) {
@@ -130,13 +134,12 @@ NameLsa::writeLog()
_LOG_DEBUG("name_lsa_end");
}
CoordinateLsa::CoordinateLsa(const ndn::Name& origR, const string lst,
uint32_t lsn,
CoordinateLsa::CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
double r, double theta)
: Lsa(CoordinateLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsType = lst;
m_lsSeqNo = lsn;
m_expirationTimePoint = lt;
m_corRad = r;
@@ -186,13 +189,17 @@ CoordinateLsa::initializeFromContent(const std::string& content)
return false;
}
try {
m_lsType = *tok_iter++;
if (*tok_iter++ != CoordinateLsa::TYPE_STRING) {
return false;
}
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++);
m_corRad = boost::lexical_cast<double>(*tok_iter++);
m_corTheta = boost::lexical_cast<double>(*tok_iter++);
}
catch (std::exception& e) {
_LOG_ERROR(e.what());
return false;
}
return true;
@@ -210,12 +217,12 @@ CoordinateLsa::writeLog()
_LOG_DEBUG(" Hyperbolic Theta: " << m_corTheta);
}
AdjLsa::AdjLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
AdjLsa::AdjLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
uint32_t nl , AdjacencyList& adl)
: Lsa(AdjLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsType = lst;
m_lsSeqNo = lsn;
m_expirationTimePoint = lt;
m_noLink = nl;
@@ -276,12 +283,16 @@ AdjLsa::initializeFromContent(const std::string& content)
return false;
}
try {
m_lsType = *tok_iter++;
if (*tok_iter++ != AdjLsa::TYPE_STRING) {
return false;
}
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++);
numLink = boost::lexical_cast<uint32_t>(*tok_iter++);
}
catch (std::exception& e) {
_LOG_ERROR(e.what());
return false;
}
for (uint32_t i = 0; i < numLink; i++) {
@@ -293,6 +304,7 @@ AdjLsa::initializeFromContent(const std::string& content)
addAdjacent(adjacent);
}
catch (std::exception& e) {
_LOG_ERROR(e.what());
return false;
}
}
@@ -320,22 +332,30 @@ AdjLsa::removeNptEntries(Nlsr& pnlsr)
void
AdjLsa::writeLog()
{
_LOG_DEBUG("Adj Lsa: ");
_LOG_DEBUG(" Origination Router: " << m_origRouter);
_LOG_DEBUG(" Ls Type: " << m_lsType);
_LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo);
_LOG_DEBUG(" Ls Lifetime: " << m_expirationTimePoint);
_LOG_DEBUG(" Adjacents: ");
int i = 1;
std::list<Adjacent> al = m_adl.getAdjList();
for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++)
{
_LOG_DEBUG(" Adjacent " << i << ": ");;
_LOG_DEBUG(" Adjacent Name: " << (*it).getName());
_LOG_DEBUG(" Connecting FaceUri: " << (*it).getConnectingFaceUri());
_LOG_DEBUG(" Link Cost: " << (*it).getLinkCost());
}
_LOG_DEBUG("adj_lsa_end");
_LOG_DEBUG(*this);
}
}//namespace nlsr
std::ostream&
operator<<(std::ostream& os, const AdjLsa& adjLsa)
{
os << "Adj Lsa:\n"
<< " Origination Router: " << adjLsa.getOrigRouter() << "\n"
<< " Ls Type: " << adjLsa.getLsType() << "\n"
<< " Ls Seq No: " << adjLsa.getLsSeqNo() << "\n"
<< " Ls Lifetime: " << adjLsa.getExpirationTimePoint() << "\n"
<< " Adjacents: \n";
int adjacencyIndex = 1;
for (const Adjacent& adjacency : adjLsa) {
os << " Adjacent " << adjacencyIndex++ << ":\n"
<< " Adjacent Name: " << adjacency.getName() << "\n"
<< " Connecting FaceUri: " << adjacency.getConnectingFaceUri() << "\n"
<< " Link Cost: " << adjacency.getLinkCost() << "\n";
}
os << "adj_lsa_end";
return os;
}
} // namespace nlsr
+30 -19
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -32,24 +32,20 @@
namespace nlsr {
class Nlsr;
class Lsa
{
public:
Lsa()
Lsa(const std::string& lsaType)
: m_origRouter()
, m_lsType(lsaType)
, m_lsSeqNo()
, m_expirationTimePoint()
, m_expiringEventId()
{
}
void
setLsType(const std::string& lst)
{
m_lsType = lst;
}
const std::string&
getLsType() const
{
@@ -106,7 +102,7 @@ public:
protected:
ndn::Name m_origRouter;
std::string m_lsType;
const std::string m_lsType;
uint32_t m_lsSeqNo;
ndn::time::system_clock::TimePoint m_expirationTimePoint;
ndn::EventId m_expiringEventId;
@@ -116,13 +112,12 @@ class NameLsa: public Lsa
{
public:
NameLsa()
: Lsa()
: Lsa(NameLsa::TYPE_STRING)
, m_npl()
{
setLsType(NameLsa::TYPE_STRING);
}
NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
NameLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
NamePrefixList& npl);
@@ -165,14 +160,15 @@ public:
class AdjLsa: public Lsa
{
public:
typedef AdjacencyList::const_iterator const_iterator;
AdjLsa()
: Lsa()
: Lsa(AdjLsa::TYPE_STRING)
, m_adl()
{
setLsType(AdjLsa::TYPE_STRING);
}
AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
AdjLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
uint32_t nl , AdjacencyList& adl);
@@ -215,6 +211,19 @@ public:
void
writeLog();
public:
const_iterator
begin() const
{
return m_adl.begin();
}
const_iterator
end() const
{
return m_adl.end();
}
private:
uint32_t m_noLink;
AdjacencyList m_adl;
@@ -227,14 +236,13 @@ class CoordinateLsa: public Lsa
{
public:
CoordinateLsa()
: Lsa()
: Lsa(CoordinateLsa::TYPE_STRING)
, m_corRad(0)
, m_corTheta(0)
{
setLsType(CoordinateLsa::TYPE_STRING);
}
CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
double r, double theta);
@@ -285,6 +293,9 @@ public:
static const std::string TYPE_STRING;
};
std::ostream&
operator<<(std::ostream& os, const AdjLsa& adjLsa);
}//namespace nlsr
#endif //NLSR_LSA_HPP
+175 -140
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -19,24 +19,114 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include <string>
#include <utility>
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "conf-parameter.hpp"
#include "utility/name-helper.hpp"
#include "logger.hpp"
#include "nlsr.hpp"
#include "publisher/segment-publisher.hpp"
#include "utility/name-helper.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/util/segment-fetcher.hpp>
#include <string>
namespace nlsr {
INIT_LOGGER("Lsdb");
class LsaContentPublisher : public SegmentPublisher<ndn::Face>
{
public:
LsaContentPublisher(ndn::Face& face,
ndn::KeyChain& keyChain,
const ndn::time::milliseconds& freshnessPeriod,
const std::string& content)
: SegmentPublisher(face, keyChain, freshnessPeriod)
, m_content(content)
{
}
virtual size_t
generate(ndn::EncodingBuffer& outBuffer) {
size_t totalLength = 0;
totalLength += outBuffer.prependByteArray(reinterpret_cast<const uint8_t*>(m_content.c_str()),
m_content.size());
return totalLength;
}
private:
const std::string m_content;
};
const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
using namespace std;
Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
: m_nlsr(nlsr)
, m_scheduler(scheduler)
, m_sync(sync)
, m_lsaRefreshTime(0)
, m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
{
}
void
Lsdb::onFetchLsaError(uint32_t errorCode,
const std::string& msg,
ndn::Name& interestName,
uint32_t retransmitNo,
const ndn::time::steady_clock::TimePoint& deadline,
ndn::Name lsaName,
uint64_t seqNo)
{
_LOG_DEBUG("Failed to fetch LSA: " << lsaName << ", Error code: " << errorCode
<< ", Message: " << msg);
if (ndn::time::steady_clock::now() < deadline) {
SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
if (it != m_highestSeqNo.end() && it->second == seqNo) {
// If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express
// immediately since at the least the LSA Interest lifetime has elapsed.
// Otherwise, it is necessary to delay the Interest re-expression to prevent
// the potential for constant Interest flooding.
ndn::time::seconds delay = m_nlsr.getConfParameter().getLsaInterestLifetime();
if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) {
delay = ndn::time::seconds(0);
}
m_scheduler.scheduleEvent(delay, std::bind(&Lsdb::expressInterest, this,
interestName, retransmitNo + 1, deadline));
}
}
}
void
Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, ndn::Name& interestName)
{
shared_ptr<ndn::Data> data = make_shared<ndn::Data>(ndn::Name(interestName));
data->setContent(bufferPtr);
_LOG_DEBUG("Received data for LSA(name): " << data->getName());
ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
uint64_t seqNo = interestName[-1].toNumber();
if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
m_highestSeqNo[lsaName] = seqNo;
}
else if (seqNo > m_highestSeqNo[lsaName]) {
m_highestSeqNo[lsaName] = seqNo;
}
else if (seqNo < m_highestSeqNo[lsaName]) {
return;
}
onContentValidated(data);
}
void
Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
@@ -50,12 +140,10 @@ nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
return nlsa1.getKey() == key;
}
bool
Lsdb::buildAndInstallOwnNameLsa()
{
NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
NameLsa::TYPE_STRING,
m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getNamePrefixList());
@@ -267,13 +355,19 @@ bool
Lsdb::buildAndInstallOwnCoordinateLsa()
{
CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
CoordinateLsa::TYPE_STRING,
m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getConfParameter().getCorR(),
m_nlsr.getConfParameter().getCorTheta());
m_nlsr.getSequencingManager().increaseCorLsaSeq();
// Sync coordinate LSAs if using HR or HR dry run.
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_nlsr.getSequencingManager().increaseCorLsaSeq();
m_sync.publishRoutingUpdate();
}
installCoordinateLsa(corLsa);
return true;
}
@@ -324,11 +418,12 @@ Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
clsa.writeLog();
addCoordinateLsa(clsa);
// Register the LSA's origin router prefix
if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
clsa.getOrigRouter());
}
if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
@@ -392,12 +487,12 @@ Lsdb::removeCoordinateLsa(const ndn::Name& key)
_1, key));
if (it != m_corLsdb.end()) {
_LOG_DEBUG("Deleting Coordinate Lsa");
(*it).writeLog();
if ((*it).getOrigRouter() !=
m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
(*it).getOrigRouter());
it->writeLog();
if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter());
}
m_corLsdb.erase(it);
return true;
}
@@ -446,6 +541,11 @@ Lsdb::scheduleAdjLsaBuild()
{
m_nlsr.incrementAdjBuildCount();
if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
// Don't build adjacency LSAs in hyperbolic routing
return;
}
if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
_LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
@@ -457,32 +557,37 @@ Lsdb::scheduleAdjLsaBuild()
void
Lsdb::buildAdjLsa()
{
_LOG_TRACE("buildAdjLsa called");
_LOG_TRACE("Lsdb::buildAdjLsa called");
m_nlsr.setIsBuildAdjLsaSheduled(false);
if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr.getConfParameter().getInterestRetryNumber())) {
int adjBuildCount = m_nlsr.getAdjBuildCount();
// Is the adjacency LSA build still necessary, or has another build
// fulfilled this request?
if (adjBuildCount > 0) {
if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
_LOG_DEBUG("Building and installing Adj LSA");
_LOG_DEBUG("Building and installing own Adj LSA");
buildAndInstallOwnAdjLsa();
}
else {
_LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors")
ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
key.append(AdjLsa::TYPE_STRING);
removeAdjLsa(key);
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
// Since more adjacency LSA builds may have been scheduled while this build
// was in progress, decrease the build count by the number of scheduled
// builds at the beginning of this build.
m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
}
}
else {
m_nlsr.setIsBuildAdjLsaSheduled(true);
int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
m_nlsr.getConfParameter().getInterestResendTime();
m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
ndn::bind(&Lsdb::buildAdjLsa, this));
}
}
@@ -589,15 +694,16 @@ bool
Lsdb::buildAndInstallOwnAdjLsa()
{
AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
AdjLsa::TYPE_STRING,
m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
m_nlsr.getAdjacencyList());
m_nlsr.getSequencingManager().increaseAdjLsaSeq();
m_sync.publishRoutingUpdate();
//Sync adjacency LSAs if link-state or dry-run HR is enabled.
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
m_nlsr.getSequencingManager().increaseAdjLsaSeq();
m_sync.publishRoutingUpdate();
}
return installAdjLsa(adjLsa);
}
@@ -643,7 +749,7 @@ Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
}
void
Lsdb::setThisRouterPrefix(string trp)
Lsdb::setThisRouterPrefix(std::string trp)
{
m_thisRouterPrefix = trp;
}
@@ -729,7 +835,10 @@ Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
_LOG_DEBUG("Deleting Coordinate Lsa");
chkCorLsa->writeLog();
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
}
chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
_LOG_DEBUG("Adding Coordinate Lsa");
chkCorLsa->writeLog();
@@ -738,20 +847,22 @@ Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
chkCorLsa->getKey(),
chkCorLsa->getLsSeqNo(),
m_lsaRefreshTime));
m_sync.publishRoutingUpdate();
// Only sync coordinate LSAs if link-state routing is disabled
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sync.publishRoutingUpdate();
}
}
else {
_LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
removeCoordinateLsa(lsaKey);
}
if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
}
}
}
void
Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
steady_clock::TimePoint deadline)
@@ -761,8 +872,6 @@ Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
}
ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
ndn::Interest interest(interestName);
uint64_t seqNo = interestName[-1].toNumber();
if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
@@ -775,14 +884,15 @@ Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
return;
}
ndn::Interest interest(interestName);
interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
_LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo);
m_nlsr.getNlsrFace().expressInterest(interest,
ndn::bind(&Lsdb::onContent,
this, _2, deadline, lsaName, seqNo),
ndn::bind(&Lsdb::processInterestTimedOut,
this, _1, timeoutCount, deadline, lsaName, seqNo));
_LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
ndn::util::SegmentFetcher::fetch(m_nlsr.getNlsrFace(), interest,
m_nlsr.getValidator(),
ndn::bind(&Lsdb::afterFetchLsa, this, _1, interestName),
ndn::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
timeoutCount, deadline, lsaName, seqNo));
}
void
@@ -791,7 +901,7 @@ Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
const ndn::Name& interestName(interest.getName());
_LOG_DEBUG("Interest received for LSA: " << interestName);
string chkString("LSA");
std::string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
if (lsaPosition >= 0) {
@@ -823,16 +933,12 @@ Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
void
Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
{
ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
data->setName(ndn::Name(interest.getName()).appendVersion());
data->setFreshnessPeriod(m_lsaRefreshTime);
data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
ndn::SignatureSha256WithRsa signature(data->getSignature());
ndn::Name signingCertName = signature.getKeyLocator().getName();
_LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
_LOG_DEBUG("Data signed with: " << signingCertName);
m_nlsr.getNlsrFace().put(*data);
LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
m_nlsr.getKeyChain(),
m_lsaRefreshTime,
content);
publisher.publish(interest.getName(),
ndn::security::signingByCertificate(m_nlsr.getDefaultCertName()));
}
void
@@ -854,6 +960,10 @@ Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
const ndn::Name& lsaKey,
uint64_t seqNo)
{
if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
_LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled.");
}
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
if (adjLsa != 0) {
if (adjLsa->getLsSeqNo() == seqNo) {
@@ -868,6 +978,10 @@ Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
const ndn::Name& lsaKey,
uint64_t seqNo)
{
if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
_LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled.");
}
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
if (corLsa != 0) {
if (corLsa->getLsSeqNo() == seqNo) {
@@ -877,59 +991,24 @@ Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
}
}
void
Lsdb::onContent(const ndn::Data& data,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo)
{
_LOG_DEBUG("Received data for LSA(name): " << data.getName());
if (data.getSignature().hasKeyLocator()) {
if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
_LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
}
}
m_nlsr.getValidator().validate(data,
ndn::bind(&Lsdb::onContentValidated, this, _1),
ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
deadline, lsaName, seqNo));
}
void
Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo)
{
_LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
if (data->getSignature().hasKeyLocator()) {
if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
_LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
}
}
m_nlsr.getValidator().validate(*data,
ndn::bind(&Lsdb::onContentValidated, this, _1),
ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
deadline, lsaName, seqNo));
}
void
Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
{
const ndn::Name& dataName = data->getName();
_LOG_DEBUG("Data validation successful for LSA: " << dataName);
string chkString("LSA");
std::string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
if (lsaPosition >= 0) {
ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4));
originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
uint64_t seqNo = dataName[-2].toNumber();
string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
uint64_t seqNo = dataName[-1].toNumber();
std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
std::string interestedLsType = dataName[-3].toUri();
std::string interestedLsType = dataName[-2].toUri();
if (interestedLsType == NameLsa::TYPE_STRING) {
processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
@@ -946,32 +1025,6 @@ Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
}
}
void
Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& msg,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo)
{
_LOG_DEBUG("Validation Error: " << msg);
// Delay re-validation by LSA Interest Lifetime. When error callback will have an error
// code, re-validation should be done only when some keys from certification chain failed
// to be fetched. After that change, delaying will no longer be necessary.
// Stop retrying if delayed re-validation will be scheduled pass the deadline
if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
if (it != m_highestSeqNo.end() && it->second == seqNo) {
_LOG_DEBUG("Scheduling revalidation attempt");
m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
ndn::bind(&Lsdb::retryContentValidation, this, data,
deadline, lsaName, seqNo));
}
}
}
void
Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
uint64_t lsSeqNo, std::string& dataContent)
@@ -1017,24 +1070,6 @@ Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
}
}
void
Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo)
{
const ndn::Name& interestName = interest.getName();
_LOG_DEBUG("Interest timed out for LSA: " << interestName);
if (ndn::time::steady_clock::now() < deadline) {
SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
if (it != m_highestSeqNo.end() && it->second == seqNo) {
expressInterest(interestName, retransmitNo + 1, deadline);
}
}
}
ndn::time::system_clock::TimePoint
Lsdb::getLsaExpirationTimePoint()
{
+43 -47
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -24,6 +24,7 @@
#include <utility>
#include <boost/cstdint.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/time.hpp>
@@ -41,19 +42,12 @@ class SyncLogicHandler;
class Lsdb
{
public:
Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
: m_nlsr(nlsr)
, m_scheduler(scheduler)
, m_sync(sync)
, m_lsaRefreshTime(0)
, m_adjLsaBuildInterval(static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT))
{
}
Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync);
bool
doesLsaExist(const ndn::Name& key, const std::string& lsType);
// function related to Name LSDB
// functions related to Name LSDB
bool
buildAndInstallOwnNameLsa();
@@ -75,7 +69,7 @@ public:
const std::list<NameLsa>&
getNameLsdb();
//function related to Cor LSDB
// functions related to Cor LSDB
bool
buildAndInstallOwnCoordinateLsa();
@@ -97,8 +91,7 @@ public:
const std::list<CoordinateLsa>&
getCoordinateLsdb();
//function related to Adj LSDB
// functions related to Adj LSDB
void
scheduleAdjLsaBuild();
@@ -141,6 +134,13 @@ public:
void
setThisRouterPrefix(std::string trp);
void
expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
void
processInterest(const ndn::Name& name, const ndn::Interest& interest);
private:
bool
addNameLsa(NameLsa& nlsa);
@@ -187,15 +187,7 @@ private:
void
exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
uint64_t seqNo);
public:
void
expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
void
processInterest(const ndn::Name& name, const ndn::Interest& interest);
private:
void
putLsaData(const ndn::Interest& interest, const std::string& content);
@@ -214,32 +206,9 @@ private:
const ndn::Name& lsaKey,
uint64_t seqNo);
void
onContent(const ndn::Data& data, const steady_clock::TimePoint& deadline,
ndn::Name lsaName, uint64_t seqNo);
/**
* @brief Retry validation after it fails
*
* Data packet validation can fail either because the packet does not have
* valid signature (fatal) or because some of the certificate chain Data packets
* failed to be fetched (non-fatal). Currently, the library does not provide
* clear indication (besides plain-text message in error callback) of what is
* the reason for failure and we will try to re-validate for as long as it the deadline.
*/
void
retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo);
void
onContentValidated(const ndn::shared_ptr<const ndn::Data>& data);
void
onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, const std::string& msg,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo);
void
processContentNameLsa(const ndn::Name& lsaKey,
uint64_t lsSeqNo, std::string& dataContent);
@@ -253,10 +222,37 @@ private:
uint64_t lsSeqNo, std::string& dataContent);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Error callback when SegmentFetcher fails to return an LSA
*
* In all error cases, a reattempt to fetch the LSA will be made.
*
* Segment validation can fail either because the packet does not have a
* valid signature (fatal) or because some of the certificates in the trust chain
* could not be fetched (non-fatal).
*
* Currently, the library does not provide clear indication (besides a plain-text message
* in the error callback) of the reason for the failure nor the segment that failed
* to be validated, thus we will continue to try to fetch the LSA until the deadline
* is reached.
*/
void
processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
const steady_clock::TimePoint& deadline, ndn::Name lsaName,
uint64_t seqNo);
onFetchLsaError(uint32_t errorCode,
const std::string& msg,
ndn::Name& interestName,
uint32_t retransmitNo,
const ndn::time::steady_clock::TimePoint& deadline,
ndn::Name lsaName,
uint64_t seqNo);
/**
* @brief Success callback when SegmentFetcher returns a valid LSA
*
* \param The base Interest used to fetch the LSA in the format:
* /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo>
*/
void
afterFetchLsa(const ndn::ConstBufferPtr& data, ndn::Name& interestName);
private:
system_clock::TimePoint
+19 -58
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -19,39 +19,27 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include <ndn-cxx/util/scheduler.hpp>
#include "conf-file-processor.hpp"
#include "logger.hpp"
#include "nlsr.hpp"
#include "nlsr-runner.hpp"
#include "version.hpp"
// boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ...
#include <boost/asio.hpp>
#include <boost/cstdint.hpp>
namespace nlsr {
int
main(int32_t argc, char** argv)
{
boost::asio::io_service ioService;
ndn::Scheduler scheduler(ioService);
ndn::Face face(ioService);
Nlsr nlsr(ioService, scheduler, face);
using namespace nlsr;
std::string programName(argv[0]);
nlsr.setConfFileName("nlsr.conf");
std::string configFileName = "nlsr.conf";
bool isDaemonProcess = false;
int32_t opt;
while ((opt = getopt(argc, argv, "df:hV")) != -1) {
switch (opt)
{
switch (opt) {
case 'f':
nlsr.setConfFileName(optarg);
configFileName = optarg;
break;
case 'd':
nlsr.setIsDaemonProcess(true);
isDaemonProcess = true;
break;
case 'V':
std::cout << NLSR_VERSION_BUILD_STRING << std::endl;
@@ -59,47 +47,20 @@ main(int32_t argc, char** argv)
break;
case 'h':
default:
nlsr.usage(programName);
NlsrRunner::printUsage(programName);
return EXIT_FAILURE;
}
}
}
ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
if (!cfp.processConfFile()) {
std::cerr << "Error in configuration file processing! Exiting from NLSR" << std::endl;
NlsrRunner runner(configFileName, isDaemonProcess);
try {
runner.run();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
if (nlsr.getConfParameter().isLog4CxxConfAvailable()) {
INIT_LOG4CXX(nlsr.getConfParameter().getLog4CxxConfPath());
}
else {
INIT_LOGGERS(nlsr.getConfParameter().getLogDir(), nlsr.getConfParameter().getLogLevel());
}
INIT_LOGGER("Main");
nlsr.initialize();
if (nlsr.getIsSetDaemonProcess()) {
nlsr.daemonize();
}
try {
nlsr.startEventLoop();
}
catch (std::exception& e) {
_LOG_FATAL("ERROR: " << e.what());
std::cerr << "ERROR: " << e.what() << std::endl;
nlsr.getFib().clean();
nlsr.destroyFaces();
}
return EXIT_SUCCESS;
}
} // namespace nlsr
int
main(int32_t argc, char** argv)
{
return nlsr::main(argc, argv);
}
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+85
View File
@@ -0,0 +1,85 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "nlsr-runner.hpp"
#include "conf-file-processor.hpp"
#include "logger.hpp"
namespace nlsr {
INIT_LOGGER("NlsrRunner");
NlsrRunner::NlsrRunner(std::string& configFileName, bool isDaemonProcess)
: m_scheduler(m_ioService)
, m_face(m_ioService)
, m_nlsr(m_ioService, m_scheduler, m_face)
{
m_nlsr.setConfFileName(configFileName);
m_nlsr.setIsDaemonProcess(isDaemonProcess);
}
void
NlsrRunner::run()
{
ConfFileProcessor configProcessor(m_nlsr, m_nlsr.getConfFileName());
if (!configProcessor.processConfFile()) {
throw Error("Error in configuration file processing! Exiting from NLSR");
}
if (m_nlsr.getConfParameter().isLog4CxxConfAvailable()) {
INIT_LOG4CXX(m_nlsr.getConfParameter().getLog4CxxConfPath());
}
else {
INIT_LOGGERS(m_nlsr.getConfParameter().getLogDir(), m_nlsr.getConfParameter().getLogLevel());
}
m_nlsr.initialize();
if (m_nlsr.getIsSetDaemonProcess()) {
m_nlsr.daemonize();
}
try {
m_nlsr.startEventLoop();
}
catch (std::exception& e) {
_LOG_FATAL("ERROR: " << e.what());
std::cerr << "ERROR: " << e.what() << std::endl;
m_nlsr.getFib().clean();
m_nlsr.destroyFaces();
}
}
void
NlsrRunner::printUsage(const std::string& programName)
{
std::cout << "Usage: " << programName << " [OPTIONS...]" << std::endl;
std::cout << " NDN routing...." << std::endl;
std::cout << " -d Run in daemon mode" << std::endl;
std::cout << " -f <FILE> Specify configuration file name" << std::endl;
std::cout << " -V Display version information" << std::endl;
std::cout << " -h Display this help message" << std::endl;
}
} // namespace nlsr
+66
View File
@@ -0,0 +1,66 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef NLSR_NLSR_RUNNER_HPP
#define NLSR_NLSR_RUNNER_HPP
#include "nlsr.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
// boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ...
#include <boost/asio.hpp>
namespace nlsr {
class NlsrRunner
{
public:
class Error : public std::runtime_error
{
public:
explicit
Error(const std::string& what)
: std::runtime_error(what)
{
}
};
NlsrRunner(std::string& configFileName, bool isDaemonProcess);
void
run();
static void
printUsage(const std::string& programName);
private:
boost::asio::io_service m_ioService;
ndn::Scheduler m_scheduler;
ndn::Face m_face;
Nlsr m_nlsr;
};
} // namespace nlsr
#endif // NLSR_NLSR_RUNNER_HPP
+40 -42
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -57,11 +57,10 @@ Nlsr::Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::F
, m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
, m_namePrefixTable(*this)
, m_syncLogicHandler(m_nlsrFace, m_nlsrLsdb, m_confParam, m_sequencingManager)
, m_helloProtocol(*this, scheduler)
, m_lsdbDatasetHandler(m_nlsrLsdb,
m_nlsrFace,
m_confParam.getRouterPrefix(),
m_keyChain)
, m_helloProtocol(*this, scheduler)
, m_certificateCache(new ndn::CertificateCacheTtl(ioService))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache, m_certStore)
, m_prefixUpdateProcessor(m_nlsrFace,
@@ -111,11 +110,11 @@ Nlsr::setInfoInterestFilter()
ndn::Name name(m_confParam.getRouterPrefix());
_LOG_DEBUG("Setting interest filter for name: " << name);
getNlsrFace().setInterestFilter(name,
ndn::bind(&HelloProtocol::processInterest,
std::bind(&HelloProtocol::processInterest,
&m_helloProtocol, _1, _2),
ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
ndn::bind(&Nlsr::registrationFailed, this, _1),
m_defaultIdentity,
std::bind(&Nlsr::onRegistrationSuccess, this, _1),
std::bind(&Nlsr::registrationFailed, this, _1),
m_signingInfo,
ndn::nfd::ROUTE_FLAG_CAPTURE);
}
@@ -127,20 +126,22 @@ Nlsr::setLsaInterestFilter()
name.append(m_confParam.getRouterName());
_LOG_DEBUG("Setting interest filter for name: " << name);
getNlsrFace().setInterestFilter(name,
ndn::bind(&Lsdb::processInterest,
std::bind(&Lsdb::processInterest,
&m_nlsrLsdb, _1, _2),
ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
ndn::bind(&Nlsr::registrationFailed, this, _1),
m_defaultIdentity,
std::bind(&Nlsr::onRegistrationSuccess, this, _1),
std::bind(&Nlsr::registrationFailed, this, _1),
m_signingInfo,
ndn::nfd::ROUTE_FLAG_CAPTURE);
}
void
Nlsr::setStrategies()
{
std::string strategy("ndn:/localhost/nfd/strategy/broadcast");
const std::string strategy("ndn:/localhost/nfd/strategy/multicast");
ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX;
broadcastKeyPrefix.append("KEYS");
m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy, 0);
m_fib.setStrategy(broadcastKeyPrefix, strategy, 0);
m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy, 0);
@@ -177,11 +178,12 @@ Nlsr::initialize()
{
_LOG_DEBUG("Initializing Nlsr");
m_confParam.buildRouterPrefix();
m_lsdbDatasetHandler.setRouterNameCommandPrefix(m_confParam.getRouterPrefix());
m_nlsrLsdb.setLsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()));
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
m_sequencingManager.initiateSeqNoFromFile();
m_sequencingManager.initiateSeqNoFromFile(m_confParam.getHyperbolicState());
m_syncLogicHandler.createSyncSocket(m_confParam.getChronosyncPrefix());
@@ -192,7 +194,7 @@ Nlsr::initialize()
/* Logging end */
initializeKey();
setStrategies();
_LOG_DEBUG("Default NLSR identity: " << m_defaultIdentity);
_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
setInfoInterestFilter();
setLsaInterestFilter();
@@ -202,7 +204,11 @@ Nlsr::initialize()
m_routingTable.setRoutingCalcInterval(m_confParam.getRoutingCalcInterval());
m_nlsrLsdb.buildAndInstallOwnNameLsa();
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
// Install coordinate LSAs if using HR or dry-run HR.
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
}
registerKeyPrefix();
registerLocalhostPrefix();
@@ -223,18 +229,17 @@ Nlsr::initialize()
void
Nlsr::initializeKey()
{
m_defaultIdentity = m_confParam.getRouterPrefix();
m_defaultIdentity.append("NLSR");
ndn::Name defaultIdentity = m_confParam.getRouterPrefix();
defaultIdentity.append("NLSR");
try
{
m_keyChain.deleteIdentity(m_defaultIdentity);
try {
m_keyChain.deleteIdentity(defaultIdentity);
}
catch (std::exception& e)
{
catch (std::exception& e) {
}
m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID, defaultIdentity);
ndn::Name keyName = m_keyChain.generateRsaKeyPairAsDefault(m_defaultIdentity, true);
ndn::Name keyName = m_keyChain.generateRsaKeyPairAsDefault(defaultIdentity, true);
ndn::shared_ptr<ndn::IdentityCertificate> certificate =
ndn::make_shared<ndn::IdentityCertificate>();
@@ -262,11 +267,11 @@ Nlsr::registerKeyPrefix()
ndn::Name keyPrefix = DEFAULT_BROADCAST_PREFIX;
keyPrefix.append("KEYS");
m_nlsrFace.setInterestFilter(keyPrefix,
ndn::bind(&Nlsr::onKeyInterest,
std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
ndn::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
ndn::bind(&Nlsr::registrationFailed, this, _1),
m_defaultIdentity,
std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
std::bind(&Nlsr::registrationFailed, this, _1),
m_signingInfo,
ndn::nfd::ROUTE_FLAG_CAPTURE);
}
@@ -332,8 +337,8 @@ Nlsr::destroyFaces()
for (std::list<Adjacent>::iterator it = adjacents.begin();
it != adjacents.end(); it++) {
m_fib.destroyFace((*it).getConnectingFaceUri(),
ndn::bind(&Nlsr::onDestroyFaceSuccess, this, _1),
ndn::bind(&Nlsr::onDestroyFaceFailure, this, _1, _2));
std::bind(&Nlsr::onDestroyFaceSuccess, this, _1),
std::bind(&Nlsr::onDestroyFaceFailure, this, _1, _2));
}
}
@@ -375,7 +380,12 @@ Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNo
// has met the HELLO retry threshold
adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
m_nlsrLsdb.scheduleAdjLsaBuild();
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
getRoutingTable().scheduleRoutingTableCalculation(*this);
}
else {
m_nlsrLsdb.scheduleAdjLsaBuild();
}
}
}
}
@@ -388,16 +398,4 @@ Nlsr::startEventLoop()
m_nlsrFace.processEvents();
}
void
Nlsr::usage(const string& progname)
{
std::cout << "Usage: " << progname << " [OPTIONS...]" << std::endl;
std::cout << " NDN routing...." << std::endl;
std::cout << " -d Run in daemon mode" << std::endl;
std::cout << " -f <FILE> Specify configuration file name" << std::endl;
std::cout << " -V Display version information" << std::endl;
std::cout << " -h Display this help message" << std::endl;
}
} // namespace nlsr
+11 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -88,9 +88,6 @@ public:
void
startEventLoop();
void
usage(const std::string& progname);
std::string
getConfFileName() const
{
@@ -229,6 +226,12 @@ public:
return m_syncLogicHandler;
}
LsdbDatasetInterestHandler&
getLsdbDatasetHandler()
{
return m_lsdbDatasetHandler;
}
void
initialize();
@@ -369,15 +372,17 @@ private:
Fib m_fib;
NamePrefixTable m_namePrefixTable;
SyncLogicHandler m_syncLogicHandler;
HelloProtocol m_helloProtocol;
LsdbDatasetInterestHandler m_lsdbDatasetHandler;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
HelloProtocol m_helloProtocol;
private:
ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
security::CertificateStore m_certStore;
Validator m_validator;
ndn::KeyChain m_keyChain;
ndn::Name m_defaultIdentity;
ndn::security::SigningInfo m_signingInfo;
ndn::Name m_defaultCertName;
update::PrefixUpdateProcessor m_prefixUpdateProcessor;
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -37,10 +37,8 @@ const uint32_t LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND = 501;
LsdbDatasetInterestHandler::LsdbDatasetInterestHandler(Lsdb& lsdb,
ndn::Face& face,
const ndn::Name& routerName,
ndn::KeyChain& keyChain)
: LOCALHOST_COMMAND_PREFIX(ndn::Name(Nlsr::LOCALHOST_PREFIX).append(Lsdb::NAME_COMPONENT))
, ROUTER_NAME_COMMAND_PREFIX(ndn::Name(routerName).append(Lsdb::NAME_COMPONENT))
, m_face(face)
, m_keyChain(keyChain)
, m_adjacencyLsaPublisher(lsdb, face, keyChain)
@@ -66,10 +64,10 @@ LsdbDatasetInterestHandler::startListeningOnLocalhost()
void
LsdbDatasetInterestHandler::startListeningOnRouterPrefix()
{
_LOG_DEBUG("Setting interest filter for: " << ROUTER_NAME_COMMAND_PREFIX);
m_face.setInterestFilter(ROUTER_NAME_COMMAND_PREFIX,
_LOG_DEBUG("Setting interest filter for: " << m_routerNameCommandPrefix);
m_face.setInterestFilter(m_routerNameCommandPrefix,
std::bind(&LsdbDatasetInterestHandler::onInterest, this, _2,
std::cref(ROUTER_NAME_COMMAND_PREFIX)));
std::cref(m_routerNameCommandPrefix)));
}
void
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -48,7 +48,6 @@ public:
LsdbDatasetInterestHandler(Lsdb& lsdb,
ndn::Face& face,
const ndn::Name& routerName,
ndn::KeyChain& keyChain);
void
@@ -63,10 +62,16 @@ public:
return LOCALHOST_COMMAND_PREFIX;
}
const ndn::Name&
ndn::Name&
getRouterNameCommandPrefix()
{
return ROUTER_NAME_COMMAND_PREFIX;
return m_routerNameCommandPrefix;
}
void
setRouterNameCommandPrefix(const ndn::Name& routerName) {
m_routerNameCommandPrefix = routerName;
m_routerNameCommandPrefix.append(Lsdb::NAME_COMPONENT);
}
private:
@@ -84,7 +89,7 @@ private:
private:
const ndn::Name LOCALHOST_COMMAND_PREFIX;
const ndn::Name ROUTER_NAME_COMMAND_PREFIX;
ndn::Name m_routerNameCommandPrefix;
ndn::Face& m_face;
ndn::KeyChain& m_keyChain;
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+6 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -68,7 +68,8 @@ public:
/** \brief Publish data under provided prefix
*/
void
publish(const ndn::Name& prefix)
publish(const ndn::Name& prefix,
const ndn::security::SigningInfo& signingInfo = ndn::security::KeyChain::DEFAULT_SIGNING_INFO)
{
ndn::EncodingBuffer buffer;
generate(buffer);
@@ -99,7 +100,7 @@ public:
data->setFinalBlockId(segmentName[-1]);
}
publishSegment(data);
publishSegment(data, signingInfo);
++segmentNo;
} while (segmentBegin < end);
}
@@ -112,9 +113,9 @@ protected:
private:
void
publishSegment(ndn::shared_ptr<ndn::Data>& data)
publishSegment(ndn::shared_ptr<ndn::Data>& data, const ndn::security::SigningInfo& signingInfo)
{
m_keyChain.sign(*data);
m_keyChain.sign(*data, signingInfo);
m_face.put(*data);
}
+8
View File
@@ -112,6 +112,14 @@ Map::createFromAdjLsdb(Nlsr& pnlsr)
}
}
void
Map::createFromCoordinateLsdb(Nlsr& nlsr)
{
for (CoordinateLsa lsa : nlsr.getLsdb().getCoordinateLsdb()) {
addEntry(lsa.getOrigRouter());
}
}
void
Map::reset()
{
+3
View File
@@ -50,6 +50,9 @@ public:
void
createFromAdjLsdb(Nlsr& pnlsr);
void
createFromCoordinateLsdb(Nlsr& nlsr);
const ndn::Name
getRouterNameByMappingNo(int32_t mn);
+18 -12
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,16 +17,11 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#include <list>
#include <utility>
#include "name-prefix-table-entry.hpp"
#include "common.hpp"
#include "name-prefix-table-entry.hpp"
#include "routing-table-entry.hpp"
#include "nexthop.hpp"
#include "logger.hpp"
@@ -33,8 +29,6 @@ namespace nlsr {
INIT_LOGGER("NamePrefixTableEntry");
using namespace std;
void
NamePrefixTableEntry::generateNhlfromRteList()
{
@@ -105,4 +99,16 @@ NamePrefixTableEntry::writeLog()
m_nexthopList.writeLog();
}
}//namespace nlsr
std::ostream&
operator<<(std::ostream& os, const NamePrefixTableEntry& entry)
{
os << "Name: " << entry.getNamePrefix() << "\n";
for (const RoutingTableEntry& rte : entry.getRteList()) {
os << "Destination: " << rte.getDestination() << "\n";
}
return os;
}
} // namespace nlsr
+13 -12
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,18 +17,15 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#ifndef NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
#define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
#include "routing-table-entry.hpp"
#include <list>
#include <utility>
#include <boost/cstdint.hpp>
#include "routing-table-entry.hpp"
namespace nlsr {
@@ -50,8 +48,8 @@ public:
return m_namePrefix;
}
std::list<RoutingTableEntry>&
getRteList()
const std::list<RoutingTableEntry>&
getRteList() const
{
return m_rteList;
}
@@ -97,6 +95,9 @@ private:
NexthopList m_nexthopList;
};
}//namespace nlsr
std::ostream&
operator<<(std::ostream& os, const NamePrefixTableEntry& entry);
#endif //NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
} // namespace nlsr
#endif // NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
+106 -70
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -19,56 +19,68 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "name-prefix-table.hpp"
#include "logger.hpp"
#include "nlsr.hpp"
#include "routing-table.hpp"
#include <algorithm>
#include <list>
#include <utility>
#include <algorithm>
#include "nlsr.hpp"
#include "name-prefix-table.hpp"
#include "name-prefix-table-entry.hpp"
#include "routing-table.hpp"
#include "logger.hpp"
namespace nlsr {
INIT_LOGGER("NamePrefixTable");
using namespace std;
static bool
npteCompare(NamePrefixTableEntry& npte, const ndn::Name& name)
{
return npte.getNamePrefix() == name;
}
void
NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
ndn::bind(&npteCompare, _1, name));
NptEntryList::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&npteCompare, _1, name));
if (it == m_table.end()) {
NamePrefixTableEntry newEntry(name);
newEntry.addRoutingTableEntry(rte);
newEntry.generateNhlfromRteList();
newEntry.getNexthopList().sort();
m_table.push_back(newEntry);
_LOG_TRACE("Adding origin: " << rte.getDestination() << " to new name prefix: " << name);
NamePrefixTableEntry entry(name);
entry.addRoutingTableEntry(rte);
entry.generateNhlfromRteList();
entry.getNexthopList().sort();
m_table.push_back(entry);
if (rte.getNexthopList().getSize() > 0) {
m_nlsr.getFib().update(name, newEntry.getNexthopList());
_LOG_TRACE("Updating FIB with next hops for " << entry);
m_nlsr.getFib().update(name, entry.getNexthopList());
}
}
else {
if (rte.getNexthopList().getSize() > 0) {
(*it).addRoutingTableEntry(rte);
(*it).generateNhlfromRteList();
(*it).getNexthopList().sort();
m_nlsr.getFib().update(name, (*it).getNexthopList());
_LOG_TRACE("Adding origin: " << rte.getDestination() << " to existing prefix: " << *it);
it->addRoutingTableEntry(rte);
it->generateNhlfromRteList();
it->getNexthopList().sort();
if (it->getNexthopList().getSize() > 0) {
_LOG_TRACE("Updating FIB with next hops for " << *it);
m_nlsr.getFib().update(name, it->getNexthopList());
}
else {
(*it).resetRteListNextHop();
(*it).getNexthopList().reset();
// The routing table may recalculate and add a routing table entry with no next hops to
// replace an existing routing table entry. In this case, the name prefix is no longer
// reachable through a next hop and should be removed from the FIB. But, the prefix
// should remain in the Name Prefix Table as a future routing table calculation may
// add next hops.
_LOG_TRACE(*it << " has no next hops; removing from FIB");
m_nlsr.getFib().remove(name);
}
}
@@ -77,38 +89,50 @@ NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte)
void
NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
ndn::bind(&npteCompare, _1, name));
NptEntryList::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&npteCompare, _1, name));
if (it != m_table.end()) {
ndn::Name destRouter = rte.getDestination();
(*it).removeRoutingTableEntry(rte);
if (((*it).getRteListSize() == 0) &&
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + NameLsa::TYPE_STRING),
(NameLsa::TYPE_STRING))) &&
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + AdjLsa::TYPE_STRING),
(AdjLsa::TYPE_STRING))) &&
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + CoordinateLsa::TYPE_STRING),
(CoordinateLsa::TYPE_STRING)))) {
_LOG_TRACE("Removing origin: " << rte.getDestination() << " from prefix: " << *it);
it->removeRoutingTableEntry(rte);
// If the prefix is a router prefix and it does not have any other routing table entries,
// the Adjacency/Coordinate LSA associated with that origin router has been removed from
// the LSDB and so the router prefix should be removed from the Name Prefix Table.
//
// If the prefix is an advertised name prefix:
// If another router advertises this name prefix, the RteList should have another entry
// for that router; the next hops should be recalculated and installed in the FIB.
//
// If no other router advertises this name prefix, the RteList should be empty and the
// prefix can be removed from the Name Prefix Table. Once a new Name LSA advertises this
// prefix, a new entry for the prefix will be created.
//
if (it->getRteListSize() == 0) {
_LOG_TRACE(*it << " has no routing table entries; removing from table and FIB");
m_table.erase(it);
m_nlsr.getFib().remove(name);
}
else {
(*it).generateNhlfromRteList();
m_nlsr.getFib().update(name, (*it).getNexthopList());
_LOG_TRACE(*it << " has other routing table entries; updating FIB with next hops");
it->generateNhlfromRteList();
it->getNexthopList().sort();
m_nlsr.getFib().update(name, it->getNexthopList());
}
}
}
void
NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
{
//
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0) {
addEntry(name, *(rteCheck));
_LOG_DEBUG("Adding origin: " << destRouter << " to " << name);
RoutingTableEntry* rteCheck = m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != nullptr) {
addEntry(name, *rteCheck);
}
else {
RoutingTableEntry rte(destRouter);
@@ -119,11 +143,12 @@ NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
void
NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
{
//
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0) {
removeEntry(name, *(rteCheck));
_LOG_DEBUG("Removing origin: " << destRouter << " from " << name);
RoutingTableEntry* rteCheck = m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != nullptr) {
removeEntry(name, *rteCheck);
}
else {
RoutingTableEntry rte(destRouter);
@@ -134,19 +159,23 @@ NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
void
NamePrefixTable::updateWithNewRoute()
{
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
it != m_table.end(); ++it) {
std::list<RoutingTableEntry> rteList = (*it).getRteList();
for (std::list<RoutingTableEntry>::iterator rteit = rteList.begin();
rteit != rteList.end(); ++rteit) {
_LOG_DEBUG("Updating table with newly calculated routes");
// Update each name prefix entry in the Name Prefix Table with newly calculated next hops
for (const NamePrefixTableEntry& prefixEntry : m_table) {
for (const RoutingTableEntry& routingEntry : prefixEntry.getRteList()) {
_LOG_TRACE("Updating next hops to origin: " << routingEntry.getDestination()
<< " for prefix: " << prefixEntry);
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
if (rteCheck != 0) {
addEntry((*it).getNamePrefix(), *(rteCheck));
m_nlsr.getRoutingTable().findRoutingTableEntry(routingEntry.getDestination());
if (rteCheck != nullptr) {
addEntry(prefixEntry.getNamePrefix(), *rteCheck);
}
else {
RoutingTableEntry rte((*rteit).getDestination());
addEntry((*it).getNamePrefix(), rte);
RoutingTableEntry rte(routingEntry.getDestination());
addEntry(prefixEntry.getNamePrefix(), rte);
}
}
}
@@ -155,12 +184,19 @@ NamePrefixTable::updateWithNewRoute()
void
NamePrefixTable::writeLog()
{
_LOG_DEBUG("----------------NPT----------------------");
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
it != m_table.end();
++it) {
(*it).writeLog();
}
_LOG_DEBUG(*this);
}
} //namespace nlsr
std::ostream&
operator<<(std::ostream& os, const NamePrefixTable& table)
{
os << "----------------NPT----------------------\n";
for (const NamePrefixTableEntry& entry : table) {
os << entry << std::endl;
}
return os;
}
} // namespace nlsr
+33 -10
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,25 +17,26 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#ifndef NLSR_NAME_PREFIX_TABLE_HPP
#define NLSR_NAME_PREFIX_TABLE_HPP
#include <list>
#include <boost/cstdint.hpp>
#include "name-prefix-table-entry.hpp"
#include "routing-table-entry.hpp"
#include <list>
namespace nlsr {
class Nlsr;
class NamePrefixTable
{
public:
typedef std::list<NamePrefixTableEntry> NptEntryList;
typedef NptEntryList::const_iterator const_iterator;
NamePrefixTable(Nlsr& nlsr)
: m_nlsr(nlsr)
{
@@ -52,6 +54,12 @@ public:
void
writeLog();
const_iterator
begin() const;
const_iterator
end() const;
private:
void
addEntry(const ndn::Name& name, RoutingTableEntry& rte);
@@ -64,6 +72,21 @@ private:
std::list<NamePrefixTableEntry> m_table;
};
}//namespace nlsr
inline NamePrefixTable::const_iterator
NamePrefixTable::begin() const
{
return m_table.begin();
}
#endif //NLSR_NAME_PREFIX_TABLE_HPP
inline NamePrefixTable::const_iterator
NamePrefixTable::end() const
{
return m_table.end();
}
std::ostream&
operator<<(std::ostream& os, const NamePrefixTable& table);
} // namespace nlsr
#endif // NLSR_NAME_PREFIX_TABLE_HPP
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+35 -5
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,10 +17,8 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#include <iostream>
#include <cmath>
#include "lsdb.hpp"
@@ -78,6 +77,37 @@ RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
}
}
}
// Links that do not have the same cost for both directions should have their
// costs corrected:
//
// If the cost of one side of the link is 0, both sides of the link should have their cost
// corrected to 0.
//
// Otherwise, both sides of the link should use the larger of the two costs.
//
for (size_t row = 0; row < m_nRouters; ++row) {
for (size_t col = 0; col < m_nRouters; ++col) {
double toCost = adjMatrix[row][col];
double fromCost = adjMatrix[col][row];
if (fromCost != toCost) {
double correctedCost = 0.0;
if (toCost != 0 && fromCost != 0) {
// If both sides of the link are up, use the larger cost
correctedCost = std::max(toCost, fromCost);
}
_LOG_WARN("Cost between [" << row << "][" << col << "] and [" << col << "][" << row <<
"] are not the same (" << toCost << " != " << fromCost << "). " <<
"Correcting to cost: " << correctedCost);
adjMatrix[row][col] = correctedCost;
adjMatrix[col][row] = correctedCost;
}
}
}
}
void
+15 -4
View File
@@ -49,9 +49,20 @@ RoutingTable::calculate(Nlsr& pnlsr)
if (pnlsr.getIsRoutingTableCalculating() == false) {
//setting routing table calculation
pnlsr.setIsRoutingTableCalculating(true);
if (pnlsr.getLsdb().doesLsaExist(
pnlsr.getConfParameter().getRouterPrefix().toUri() + "/" + "adjacency",
std::string("adjacency"))) {
bool isHrEnabled = pnlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF;
if ((!isHrEnabled
&&
pnlsr.getLsdb()
.doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri()
+ "/" + "adjacency", std::string("adjacency")))
||
(isHrEnabled
&&
pnlsr.getLsdb()
.doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri()
+ "/" + "coordinate", std::string("coordinate")))) {
if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
_LOG_TRACE("Clearing old routing table");
clearRoutingTable();
@@ -127,7 +138,7 @@ void
RoutingTable::calculateHypRoutingTable(Nlsr& nlsr)
{
Map map;
map.createFromAdjLsdb(nlsr);
map.createFromCoordinateLsdb(nlsr);
map.writeLog();
size_t nRouters = map.getMapSize();
@@ -1,17 +0,0 @@
#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
#include "certificate-store-entry.hpp"
namespace nlsr {
std::ostream&
operator<<(std::ostream& os, const CertificateStoreEntry& ncse)
{
os << "------Certificate Entry---------------" << std::endl;
os << *(ncse.getCert()) << std::endl;
ndn::SignatureSha256WithRsa sig(ncse.getCert()->getSignature());
ndn::Name keyName = sig.getKeyLocator().getName();
os << "Signee : " << keyName.toUri() << std::endl;
os << "Cert Seq Num: " << ncse.getCertSeqNum() << std::endl;
os << "Is Signer Verified: " << ncse.getIsSignerVerified() << std::endl;
return os;
}
}//namespace nlsr
@@ -1,72 +0,0 @@
#ifndef NLSR_CERT_STORE_ENTRY_HPP
#define NLSR_CERT_STORE_ENTRY_HPP
#include <iostream>
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/security/identity-certificate.hpp>
namespace nlsr {
class CertificateStoreEntry
{
public:
CertificateStoreEntry()
: m_cert(ndn::make_shared<ndn::IdentityCertificate>())
, m_certSeqNum(0)
, m_isSignerVerified(false)
{}
CertificateStoreEntry(ndn::shared_ptr<ndn::IdentityCertificate> pcert
, uint32_t csn, bool isv)
: m_cert(pcert)
, m_certSeqNum(csn)
, m_isSignerVerified(isv)
{}
ndn::shared_ptr<ndn::IdentityCertificate>
getCert() const
{
return m_cert;
}
void
setCert(ndn::shared_ptr<ndn::IdentityCertificate> pcert)
{
m_cert = pcert;
}
uint32_t
getCertSeqNum() const
{
return m_certSeqNum;
}
void
setCertSeqNum(uint32_t csn)
{
m_certSeqNum = csn;
}
bool
getIsSignerVerified() const
{
return m_isSignerVerified;
}
void
setIsSignerVerified(bool isv)
{
m_isSignerVerified = isv;
}
private:
ndn::shared_ptr<ndn::IdentityCertificate> m_cert;
uint32_t m_certSeqNum;
bool m_isSignerVerified;
};
/* Debugging Purpose */
std::ostream&
operator <<(std::ostream& os, const CertificateStoreEntry& ncse);
}//namespace NLSR
#endif //NLSR_CERT_STORE_ENTRY_HPP
-231
View File
@@ -1,231 +0,0 @@
#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include "certificate-store.hpp"
#include "waiting-list-entry.hpp"
#include "key-manager.hpp"
namespace nlsr {
static bool
nlsrCertificateStoreEntryCompare(CertificateStoreEntry& ncse1,
CertificateStoreEntry& ncse2)
{
int sizeDiff = ncse1.getCert()->getName().size() -
ncse2.getCert()->getName().size();
return (ncse2.getCert()->getName().isPrefixOf(ncse1.getCert()->getName()) &&
(sizeDiff <= 1 && sizeDiff >= 0));
}
static bool
nlsrCertificateStoreEntryCompareByName(CertificateStoreEntry& ncse1,
std::string compCertName)
{
ndn::Name ccn(compCertName);
int sizeDiff = ncse1.getCert()->getName().size() - ccn.size();
return (ccn.isPrefixOf(ncse1.getCert()->getName()) &&
(sizeDiff <= 1 && sizeDiff >= 0));
}
void
CertificateStore::updateWaitingList(std::string respCertName)
{
ndn::Name tmpName(respCertName);
respCertName = tmpName.getPrefix(-1).toUri();
std::pair<WaitingListEntry, bool> chkWle =
m_waitingList.getWaitingListEntry(respCertName);
if (chkWle.second)
{
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> sc =
getCertificateFromStore(respCertName);
std::list<std::string> waitees = (chkWle.first).getWaitingCerts();
for (std::list<std::string>::iterator it = waitees.begin();
it != waitees.end(); ++it)
{
KeyManager km;
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> wc =
getCertificateFromStore(*(it));
if (wc.second && sc.second)
{
if (km.verifySignature(*(wc.first), sc.first->getPublicKeyInfo()))
{
//1. Update Certificate Store
setCertificateIsVerified(*(it), true);
//2. Call updateWaitingList for waitee ( *(it) )
updateWaitingList(*(it));
}
}
}
}
//remove that entry from waiting list
m_waitingList.remove(respCertName);
}
void
CertificateStore::updateWaitingList(CertificateStoreEntry& ncse)
{
if (ncse.getIsSignerVerified())
{
updateWaitingList(ncse.getCert()->getName().toUri());
}
else
{
ndn::SignatureSha256WithRsa signature(ncse.getCert()->getSignature());
m_waitingList.add(signature.getKeyLocator().getName().toUri(),
ncse.getCert()->getName().toUri());
}
}
bool
CertificateStore::addCertificate(CertificateStoreEntry& ncse)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompare, _1, ncse));
if (it == m_certTable.end())
{
m_certTable.push_back(ncse);
updateWaitingList(ncse);
return true;
}
else if (it != m_certTable.end())
{
if ((*it).getCertSeqNum() < ncse.getCertSeqNum())
{
m_certTable.erase(it);
m_certTable.push_back(ncse);
updateWaitingList(ncse);
return true;
}
}
return false;
}
bool
CertificateStore::addCertificate(
ndn::shared_ptr<ndn::IdentityCertificate> pcert, uint32_t csn, bool isv)
{
CertificateStoreEntry ncse(pcert, csn, isv);
return addCertificate(ncse);
}
std::pair<uint32_t, bool>
CertificateStore::getCertificateSeqNum(std::string certName)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it == m_certTable.end())
{
return std::make_pair(0, false);
}
return std::make_pair((*it).getCertSeqNum(), true);
}
void
CertificateStore::setCertificateIsVerified(std::string certName,
bool isVerified)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it != m_certTable.end())
{
it->setIsSignerVerified(true);
}
}
bool
CertificateStore::getCertificateIsVerified(std::string certName)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it != m_certTable.end())
{
return it->getIsSignerVerified();
}
return false;
}
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
CertificateStore::getCertificateFromStore(const std::string certName)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it == m_certTable.end())
{
ndn::shared_ptr<ndn::IdentityCertificate> cert =
ndn::make_shared<ndn::IdentityCertificate>();
return std::make_pair(cert, false);
}
return std::make_pair((*it).getCert(), true);
}
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
CertificateStore::getCertificateFromStore(
const std::string certName, uint64_t checkSeqNum)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it == m_certTable.end())
{
ndn::shared_ptr<ndn::IdentityCertificate> cert =
ndn::make_shared<ndn::IdentityCertificate>();
return std::make_pair(cert, false);
}
else
{
if ((*it).getCertSeqNum() == checkSeqNum)
{
return std::make_pair((*it).getCert(), true);
}
}
return std::make_pair((*it).getCert(), false);
}
bool
CertificateStore::isCertificateNewInStore(const std::string certName,
int checkSeqNo)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it != m_certTable.end())
{
return (*it).getCertSeqNum() < checkSeqNo ;
}
return true;
}
bool
CertificateStore::removeCertificateFromStroe(const std::string certName)
{
std::list<CertificateStoreEntry>::iterator it =
std::find_if(m_certTable.begin(), m_certTable.end(),
bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
if (it != m_certTable.end())
{
m_certTable.erase(it);
return true;
}
return false;
}
void
CertificateStore::print()
{
std::list<CertificateStoreEntry>::iterator it;
for (it = m_certTable.begin(); it != m_certTable.end(); ++it)
{
std::cout << (*it) << std::endl;
}
std::cout << m_waitingList << std::endl;
}
} //namespace nlsr
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -1,63 +0,0 @@
#ifndef NLSR_CERT_STORE_HPP
#define NLSR_CERT_STORE_HPP
#include <list>
#include <ndn-cpp-dev/security/identity-certificate.hpp>
#include "certificate-store-entry.hpp"
#include "waiting-list.hpp"
namespace nlsr {
class CertificateStore
{
public:
CertificateStore()
: m_certTable()
, m_waitingList()
{}
bool
addCertificate(CertificateStoreEntry& ncse);
bool
addCertificate(ndn::shared_ptr<ndn::IdentityCertificate> pcert
, uint32_t csn, bool isv);
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
getCertificateFromStore(const std::string certName);
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
getCertificateFromStore(const std::string certName, uint64_t checkSeqNum);
bool
removeCertificateFromStroe(const std::string certName);
bool
isCertificateNewInStore(const std::string certName, int checkSeqNo);
std::pair<uint32_t, bool>
getCertificateSeqNum(std::string certName);
void
print();
void
setCertificateIsVerified(std::string certName, bool isVerified);
bool
getCertificateIsVerified(std::string certName);
private:
void
updateWaitingList(CertificateStoreEntry& ncse);
void
updateWaitingList(std::string respCertName);
private:
std::list<CertificateStoreEntry> m_certTable;
WaitingList m_waitingList;
};
} //namespace nlsr
#endif // NLSR_CERT_STORE_HPP
-400
View File
@@ -1,400 +0,0 @@
#include <ndn-cpp-dev/security/identity-certificate.hpp>
#include <ndn-cpp-dev/encoding/block.hpp>
#include <ndn-cpp-dev/util/io.hpp>
#include <stdexcept>
#include "sequencing-manager.hpp"
#include "key-manager.hpp"
#include "nlsr.hpp"
namespace nlsr {
bool
KeyManager::initialize(ConfParameter& cp)
{
initCertSeqFromFile(cp.getSeqFileDir());
if (!loadAllCertificates(cp.getCertDir()))
{
return false;
}
m_nlsrRootKeyPrefix = cp.getRootKeyPrefix();
string processIdentityName(cp.getRootKeyPrefix());
processIdentityName += "/";
processIdentityName += cp.getSiteName();
processIdentityName += "/";
processIdentityName += "R.Start";
processIdentityName += "/";
processIdentityName += cp.getRouterName();
ndn::Name ri(processIdentityName);
std::cout << "Router Identity: " << ri.toUri() << std::endl;
m_routerIdentity = ri;
processIdentityName += "/";
processIdentityName += "nlsr";
cout << "Proces Identity Name: " << processIdentityName << endl;
ndn::Name identityName(processIdentityName);
m_processIdentity = identityName;
ndn::KeyChain::deleteIdentity(m_processIdentity);
m_processCertName = ndn::KeyChain::createIdentity(m_processIdentity);
cout << "Certificate Name: " << m_processCertName.toUri() << endl;
m_processKeyName = m_processCertName.getPrefix(-2);
cout << "Key Name: " << m_processKeyName.toUri() << endl;
ndn::shared_ptr<ndn::IdentityCertificate> cert =
getCertificate(m_processCertName);
signByIdentity(*(cert), m_routerIdentity);
m_certStore.addCertificate(cert, m_certSeqNo, true);
m_certStore.print();
return true;
}
bool
KeyManager::loadAllCertificates(std::string certDirPath)
{
std::string filePath = certDirPath;
if (filePath.empty())
{
SequencingManager sm;
filePath = sm.getUserHomeDirectory();
filePath += "/nlsrCertDir";
}
return loadCertificate(filePath + "/root.cert", KEY_TYPE_ROOT)
&& loadCertificate(filePath + "/site.cert", KEY_TYPE_SITE)
&& loadCertificate(filePath + "/operator.cert", KEY_TYPE_OPERATOR)
&& loadCertificate(filePath + "/router.cert", KEY_TYPE_ROUTER) ;
}
bool
KeyManager::loadCertificate(std::string inputFile, nlsrKeyType keyType)
{
try
{
ndn::shared_ptr<ndn::IdentityCertificate> cert =
ndn::io::load<ndn::IdentityCertificate>(inputFile, ndn::io::BASE_64);
ndn::Name certName = cert->getName();
switch (keyType)
{
case KEY_TYPE_ROOT:
m_certStore.addCertificate(cert, 10, true);
m_rootCertName = certName;
std::cout << "Root Cert: " << m_rootCertName << std::endl;
break;
case KEY_TYPE_SITE:
m_certStore.addCertificate(cert, 10, true);
m_siteCertName = certName;
std::cout << "Site Cert: " << m_siteCertName << std::endl;
break;
case KEY_TYPE_OPERATOR:
m_certStore.addCertificate(cert, 10, true);
m_opCertName = certName;
std::cout << "Operator Cert: " << m_opCertName << std::endl;
break;
case KEY_TYPE_ROUTER:
m_certStore.addCertificate(cert, m_certSeqNo, true);
m_routerCertName = certName;
std::cout << "Router Cert: " << m_routerCertName << std::endl;
break;
case KEY_TYPE_PROCESS:
m_certStore.addCertificate(cert, m_certSeqNo, true);
m_processCertName = certName;
std::cout << "Process Cert: " << m_processCertName << std::endl;
break;
default:
break;
}
return true;
}
catch (std::exception& e)
{
return false;
}
return false;
}
ndn::Name
KeyManager::getProcessCertName()
{
return m_processCertName;
}
ndn::Name
KeyManager::getRouterCertName()
{
return m_routerCertName;
}
ndn::Name
KeyManager::getOperatorCertName()
{
return m_opCertName;
}
ndn::Name
KeyManager::getSiteCertName()
{
return m_siteCertName;
}
ndn::Name
KeyManager::getRootCertName()
{
return m_rootCertName;
}
uint32_t
KeyManager::getCertSeqNo()
{
return m_certSeqNo;
}
void
KeyManager::setCerSeqNo(uint32_t csn)
{
m_certSeqNo = csn;
}
void
KeyManager::initCertSeqFromFile(string certSeqFileDir)
{
m_certSeqFileNameWithPath = certSeqFileDir;
if (m_certSeqFileNameWithPath.empty())
{
SequencingManager sm;
m_certSeqFileNameWithPath = sm.getUserHomeDirectory();
}
m_certSeqFileNameWithPath += "/nlsrCertSeqNo.txt";
cout << "Key Seq File Name: " << m_certSeqFileNameWithPath << endl;
std::ifstream inputFile(m_certSeqFileNameWithPath.c_str(), ios::binary);
if (inputFile.good())
{
inputFile >> m_certSeqNo;
m_certSeqNo++;
}
else
{
m_certSeqNo = 1;
}
writeCertSeqToFile();
}
void
KeyManager::writeCertSeqToFile()
{
std::ofstream outputFile(m_certSeqFileNameWithPath.c_str(), ios::binary);
outputFile << m_certSeqNo;
outputFile.close();
}
bool
KeyManager::isNewCertificate(std::string certName, int checkSeqNum)
{
return m_certStore.isCertificateNewInStore(certName, checkSeqNum);
}
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
KeyManager::getCertificateFromStore(const std::string certName, int checkSeqNum)
{
return m_certStore.getCertificateFromStore(certName, checkSeqNum);
}
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
KeyManager::getCertificateFromStore(const std::string certName)
{
return m_certStore.getCertificateFromStore(certName);
}
bool
KeyManager::addCertificate(ndn::shared_ptr<ndn::IdentityCertificate> pcert
, uint32_t csn, bool isv)
{
return m_certStore.addCertificate(pcert, csn, isv);
}
std::pair<uint32_t, bool>
KeyManager::getCertificateSeqNum(std::string certName)
{
return m_certStore.getCertificateSeqNum(certName);
}
nlsrKeyType
KeyManager::getKeyTypeFromName(const std::string keyName)
{
Tokenizer nt(keyName, "/");
std::string KEY("KEY");
std::string opHandle("O.Start");
std::string routerHandle("R.Start");
std::string processHandle("nlsr");
if (nt.getTokenString(0, nt.getTokenPosition(KEY) - 1) == m_nlsrRootKeyPrefix)
{
return KEY_TYPE_ROOT;
}
else if (nt.doesTokenExist(opHandle))
{
return KEY_TYPE_OPERATOR;
}
else if (nt.doesTokenExist(routerHandle) &&
nt.doesTokenExist(processHandle))
{
return KEY_TYPE_PROCESS;
}
else if (nt.doesTokenExist(routerHandle) &&
!nt.doesTokenExist(processHandle))
{
return KEY_TYPE_ROUTER;
}
else
{
return KEY_TYPE_SITE;
}
}
std::string
KeyManager::getRouterName(const std::string name)
{
std::string routerName;
std::string rkp(m_nlsrRootKeyPrefix);
Tokenizer ntRkp(rkp, "/");
Tokenizer nt(name, "/");
std::string KEY("KEY");
std::string opHandle("O.Start");
std::string routerHandle("R.Start");
std::string processHandle("nlsr");
std::string infoHandle("info");
std::string lsaHandle("LSA");
if (nt.doesTokenExist(processHandle) && nt.doesTokenExist(routerHandle))
{
routerName = "/ndn" +
nt.getTokenString(ntRkp.getTokenNumber(),
nt.getTokenPosition(routerHandle) - 1) +
nt.getTokenString(nt.getTokenPosition(routerHandle) + 1,
nt.getTokenPosition(processHandle) - 1);
}
else if (nt.doesTokenExist(routerHandle) && !nt.doesTokenExist(infoHandle)
&& !nt.doesTokenExist(lsaHandle))
{
routerName = "/ndn" +
nt.getTokenString(ntRkp.getTokenNumber(),
nt.getTokenPosition(routerHandle) - 1) +
nt.getTokenString(nt.getTokenPosition(routerHandle) + 1,
nt.getTokenPosition(KEY) - 1);
}
else
{
if (nt.doesTokenExist(infoHandle))
{
routerName = nt.getTokenString(0, nt.getTokenPosition(infoHandle) - 1);
}
else
{
routerName = nt.getTokenString(nt.getTokenPosition(lsaHandle) + 1,
nt.getTokenNumber() - 4);
}
}
return routerName;
}
std::string
KeyManager::getSiteName(const std::string name)
{
std::string siteName;
std::string routerName;
std::string rkp(m_nlsrRootKeyPrefix);
Tokenizer ntRkp(rkp, "/");
Tokenizer nt(name, "/");
std::string KEY("KEY");
std::string opHandle("O.Start");
std::string routerHandle("R.Start");
if (nt.doesTokenExist(routerHandle))
{
siteName = "/ndn" + nt.getTokenString(ntRkp.getTokenNumber(),
nt.getTokenPosition(routerHandle) - 1);
}
else if (nt.doesTokenExist(opHandle))
{
siteName = "/ndn" + nt.getTokenString(ntRkp.getTokenNumber(),
nt.getTokenPosition(opHandle) - 1);
}
else
{
siteName = "/ndn" + nt.getTokenString(ntRkp.getTokenNumber(),
nt.getTokenPosition(KEY) - 1);
}
return siteName;
}
std::string
KeyManager::getRootName(const std::string name)
{
std::string rName;
Tokenizer nt(name, "/");
std::string rkp(m_nlsrRootKeyPrefix);
Tokenizer ntRkp(rkp, "/");
rName = nt.getTokenString(0, ntRkp.getTokenNumber() - 1);
return rName;
}
bool
KeyManager::verifyCertPacket(Nlsr& pnlsr, ndn::IdentityCertificate& packet)
{
std::cout << "KeyManager::verifyCertPacket Called" << std::endl;
ndn::SignatureSha256WithRsa signature(packet.getSignature());
std::string signingCertName = signature.getKeyLocator().getName().toUri();
std::string packetName = packet.getName().toUri();
std::cout << "Packet Name: " << packetName << std::endl;
std::cout << "Signee Name: " << signingCertName << std::endl;
int paketCertType = getKeyTypeFromName(packetName);
int signingCertType = getKeyTypeFromName(signingCertName);
if (signingCertType > paketCertType) //lower level Cert can not sign
{
//upper level Cert
return false;
}
if ((signingCertType == paketCertType) && (paketCertType != KEY_TYPE_ROOT))
{
return false;
}
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> signee =
m_certStore.getCertificateFromStore(signingCertName);
if (signee.second)
{
switch (paketCertType)
{
case KEY_TYPE_ROOT:
return ((getRootName(packetName) == m_nlsrRootKeyPrefix) &&
verifySignature(packet, signee.first->getPublicKeyInfo()));
break;
case KEY_TYPE_SITE:
return ((getRootName(packetName) == getRootName(signingCertName)) &&
verifySignature(packet, signee.first->getPublicKeyInfo()) &&
m_certStore.getCertificateIsVerified(signingCertName));
break;
case KEY_TYPE_OPERATOR:
return ((getSiteName(packetName) == getSiteName(signingCertName)) &&
verifySignature(packet, signee.first->getPublicKeyInfo()) &&
m_certStore.getCertificateIsVerified(signingCertName));
break;
case KEY_TYPE_ROUTER:
return ((getSiteName(packetName) == getSiteName(signingCertName)) &&
verifySignature(packet, signee.first->getPublicKeyInfo()) &&
m_certStore.getCertificateIsVerified(signingCertName));
break;
case KEY_TYPE_PROCESS:
return ((getRouterName(packetName) == getRouterName(signingCertName)) &&
verifySignature(packet, signee.first->getPublicKeyInfo()) &&
m_certStore.getCertificateIsVerified(signingCertName));
break;
}
}
else
{
std::cout << "Certificate Not Found in store. Sending Interest" << std::endl;
pnlsr.getIm().expressInterest(signingCertName, 3,
pnlsr.getConfParameter().getInterestResendTime());
return false;
}
return false;
}
}//namespace nlsr
-273
View File
@@ -1,273 +0,0 @@
#ifndef NLSR_KM_HPP
#define NLSR_KM_HPP
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/data.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/util/random.hpp>
#include <ndn-cpp-dev/security/identity-certificate.hpp>
#include <list>
#include "conf-parameter.hpp"
#include "certificate-store.hpp"
#include "utility/tokenizer.hpp"
namespace nlsr {
class Nlsr;
enum nlsrKeyType
{
KEY_TYPE_ROOT,
KEY_TYPE_SITE,
KEY_TYPE_OPERATOR,
KEY_TYPE_ROUTER,
KEY_TYPE_PROCESS,
KEY_TYPE_UNKNOWN
};
enum nlsrContentType
{
CONTENT_TYPE_DATA,
CONTENT_TYPE_CERT
};
class KeyManager: public ndn::KeyChain, public ndn::Validator
{
typedef SecPublicInfo::Error InfoError;
typedef SecTpm::Error TpmError;
public:
using ndn::KeyChain::addCertificate;
KeyManager()
: m_certSeqNo(1)
, m_nlsrRootKeyPrefix()
, m_certStore()
{
}
bool
initialize(ConfParameter& cp);
void
checkPolicy(const ndn::Data& data,
int stepCount,
const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps)
{}
void
checkPolicy(const ndn::Interest& interest,
int stepCount,
const ndn::OnInterestValidated& onValidated,
const ndn::OnInterestValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps)
{}
void
signData(ndn::Data& data)
{
ndn::KeyChain::signByIdentity(data, m_processIdentity);
}
template<typename T> void
signByIdentity(T& packet, ndn::Name signeeIdentity)
{
ndn::KeyChain::signByIdentity(packet, signeeIdentity);
}
ndn::Name
createIdentity(const ndn::Name identityName)
{
return ndn::KeyChain::createIdentity(identityName);
}
ndn::Name
createIdentity(const ndn::Name identityName, const ndn::Name signee)
{
ndn::KeyChain::addIdentity(identityName);
ndn::Name keyName;
try
{
keyName = ndn::KeyChain::getDefaultKeyNameForIdentity(identityName);
}
catch (InfoError& e)
{
keyName = ndn::KeyChain::generateRSAKeyPairAsDefault(identityName, true);
}
ndn::shared_ptr<ndn::PublicKey> pubKey;
try
{
pubKey = ndn::KeyChain::getPublicKey(keyName);
}
catch (InfoError& e)
{
return identityName;
}
ndn::Name certName;
try
{
certName = ndn::KeyChain::getDefaultCertificateNameForKey(keyName);
}
catch (InfoError& e)
{
ndn::shared_ptr<ndn::IdentityCertificate> certificate =
ndn::make_shared<ndn::IdentityCertificate>();
ndn::Name certificateName = keyName.getPrefix(-1);
certificateName.append("KEY").append(
keyName.get(-1)).append("ID-CERT").appendVersion();
certificate->setName(certificateName);
certificate->setNotBefore(ndn::time::system_clock::now());
certificate->setNotAfter(ndn::time::system_clock::now() + ndn::time::days(
7300) /* 1 year*/);
certificate->setPublicKeyInfo(*pubKey);
certificate->addSubjectDescription(
ndn::CertificateSubjectDescription("2.5.4.41",
keyName.toUri()));
certificate->encode();
try
{
ndn::KeyChain::signByIdentity(*certificate, signee);
}
catch (InfoError& e)
{
try
{
ndn::KeyChain::deleteIdentity(identityName);
}
catch (InfoError& e)
{
}
return identityName;
}
certName = certificate->getName();
}
return certName;
}
void
printCertStore()
{
m_certStore.print();
}
private:
bool
verifyDataPacket(ndn::Data packet)
{
std::cout << "KeyManager::verifyDataPacket Called" << std::endl;
ndn::SignatureSha256WithRsa signature(packet.getSignature());
std::string signingCertName = signature.getKeyLocator().getName().toUri();
std::string packetName = packet.getName().toUri();
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> signee =
m_certStore.getCertificateFromStore(signingCertName);
if (signee.second)
{
std::string routerNameFromPacketName = getRouterName(packetName);
std::string routerNameFromCertName = getRouterName(signingCertName);
return ((routerNameFromPacketName == routerNameFromCertName) &&
verifySignature(packet, signee.first->getPublicKeyInfo()) &&
m_certStore.getCertificateIsVerified(signingCertName));
}
return false;
}
bool
verifyCertPacket(Nlsr& pnlsr, ndn::IdentityCertificate& packet);
public:
template<typename T> bool
verify(T& packet)
{
std::cout << "KeyManager::verify Called" << std::endl;
return verifyDataPacket(packet);
return false;
}
bool
verify(Nlsr& pnlsr, ndn::IdentityCertificate& packet)
{
return verifyCertPacket(pnlsr, packet);
}
ndn::Name
getProcessCertName();
ndn::Name
getRouterCertName();
ndn::Name
getOperatorCertName();
ndn::Name
getSiteCertName();
ndn::Name
getRootCertName();
uint32_t
getCertSeqNo();
std::pair<uint32_t, bool>
getCertificateSeqNum(std::string certName);
void
setCerSeqNo(uint32_t csn);
void
initCertSeqFromFile(std::string certSeqFileDir);
void
writeCertSeqToFile();
bool
isNewCertificate(std::string certName, int checkSeqNum);
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
getCertificateFromStore(const std::string certName, int checkSeqNum);
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
getCertificateFromStore(const std::string certName);
bool
addCertificate(ndn::shared_ptr<ndn::IdentityCertificate> pcert,
uint32_t csn, bool isv);
private:
bool
loadAllCertificates(std::string certDirPath);
bool
loadCertificate(std::string inputFile, nlsrKeyType keyType);
nlsrKeyType
getKeyTypeFromName(const std::string keyName);
std::string
getRouterName(const std::string name);
std::string
getSiteName(const std::string name);
std::string
getRootName(const std::string name);
private:
ndn::Name m_processIdentity;
ndn::Name m_routerIdentity;
ndn::Name m_processCertName;
ndn::Name m_routerCertName;
ndn::Name m_opCertName;
ndn::Name m_siteCertName;
ndn::Name m_rootCertName;
ndn::Name m_processKeyName;
uint32_t m_certSeqNo;
std::string m_certSeqFileNameWithPath;
std::string m_nlsrRootKeyPrefix;
CertificateStore m_certStore;
};
}//namespace nlsr
#endif //NLSR_KM_HPP
@@ -1,40 +0,0 @@
#include <iostream>
#include <list>
#include <ndn-cpp-dev/face.hpp>
#include "waiting-list-entry.hpp"
namespace nlsr {
static bool
waiteeCompare(std::string& w1, std::string& w2)
{
return w1 == w2 ;
}
bool
WaitingListEntry::addWaitee(std::string waiteeName)
{
std::list<std::string>::iterator it = std::find_if(m_waitingCerts.begin(),
m_waitingCerts.end(), ndn::bind(&waiteeCompare, _1, waiteeName));
if (it == m_waitingCerts.end())
{
m_waitingCerts.push_back(waiteeName);
return true;
}
return false;
}
std::ostream&
operator<<(std::ostream& os, const WaitingListEntry& we)
{
os << "-------------Wiating List Entry-------------" << std::endl;
os << "Responsible Certificate: " << we.getResponsibleCert() << std::endl;
std::list<std::string> waitee = we.getWaitingCerts();
int i = 1;
for (std::list<std::string>::iterator it = waitee.begin();
it != waitee.end(); ++i, ++it)
{
os << "Waite " << i << ": " << *(it) << std::endl;
}
return os;
}
}//namespace nlsr
@@ -1,51 +0,0 @@
#ifndef NLSR_WLE_HPP
#define NLSR_WLE_HPP
#include <list>
#include <iostream>
namespace nlsr {
class WaitingListEntry
{
public:
WaitingListEntry()
: m_responsibleCert()
, m_waitingCerts()
{}
WaitingListEntry(std::string resCert)
: m_responsibleCert(resCert)
, m_waitingCerts()
{}
std::string
getResponsibleCert() const
{
return m_responsibleCert;
}
void
setResponsibleCert(std::string resCert)
{
m_responsibleCert = resCert;
}
std::list<std::string>
getWaitingCerts() const
{
return m_waitingCerts;
}
bool
addWaitee(std::string waiteeName);
private:
std::string m_responsibleCert;
std::list<std::string> m_waitingCerts;
};
std::ostream&
operator<<(std::ostream& os, const WaitingListEntry& we);
} //end name space
#endif //NLSR_WLE_HPP
-72
View File
@@ -1,72 +0,0 @@
#include <ndn-cpp-dev/face.hpp>
#include "waiting-list.hpp"
namespace nlsr {
static bool
waitingListCompare(const WaitingListEntry& w1, const std::string& respCert)
{
return w1.getResponsibleCert() == respCert;
}
std::pair<WaitingListEntry, bool>
WaitingList::getWaitingListEntry(std::string respCert)
{
std::list<WaitingListEntry>::iterator it = std::find_if(m_waitingTable.begin(),
m_waitingTable.end(), ndn::bind(&waitingListCompare, _1, respCert));
if (it != m_waitingTable.end())
{
return std::make_pair(*(it), true);
}
WaitingListEntry wle;
return std::make_pair(wle, false);
}
bool
WaitingList::add(std::string respCert, std::string waitee)
{
std::list<WaitingListEntry>::iterator it = std::find_if(m_waitingTable.begin(),
m_waitingTable.end(), ndn::bind(&waitingListCompare, _1, respCert));
if (it == m_waitingTable.end())
{
WaitingListEntry newWle(respCert);
newWle.addWaitee(waitee);
m_waitingTable.push_back(newWle);
return true;
}
else
{
return it->addWaitee(waitee);
}
return false;
}
bool
WaitingList::remove(std::string respCert)
{
std::list<WaitingListEntry>::iterator it = std::find_if(m_waitingTable.begin(),
m_waitingTable.end(), ndn::bind(&waitingListCompare, _1, respCert));
if (it == m_waitingTable.end())
{
return false;
}
else
{
m_waitingTable.erase(it);
return true;
}
return false;
}
std::ostream&
operator<<(std::ostream& os, WaitingList wl)
{
os << "-------Waiting List--------" << std::endl;
std::list<WaitingListEntry> wles = wl.getWaitingTable();
for (std::list<WaitingListEntry> ::iterator it = wles.begin();
it != wles.end(); ++it)
{
os << *(it) << std::endl;
}
return os;
}
}//namespace nlsr
-38
View File
@@ -1,38 +0,0 @@
#ifndef NLSR_WL_HPP
#define NLSR_WL_HPP
#include "waiting-list-entry.hpp"
namespace nlsr {
class WaitingList
{
public:
WaitingList()
: m_waitingTable()
{}
std::list<WaitingListEntry>&
getWaitingTable()
{
return m_waitingTable;
}
bool
add(std::string respCert, std::string waitee);
std::pair<WaitingListEntry, bool>
getWaitingListEntry(std::string respCert);
bool
remove(std::string respCert);
private:
std::list<WaitingListEntry> m_waitingTable;
};
std::ostream&
operator<<(std::ostream& os, WaitingList wl);
}//namespace nlsr
#endif //NLSR_WL_HPP
+23 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -62,15 +62,34 @@ SequencingManager::writeSeqNoToFile() const
}
void
SequencingManager::initiateSeqNoFromFile()
SequencingManager::initiateSeqNoFromFile(int hypState)
{
_LOG_DEBUG("Seq File Name: " << m_seqFileNameWithPath);
std::ifstream inputFile(m_seqFileNameWithPath.c_str(), ios::binary);
if (inputFile.good()) {
inputFile >> m_combinedSeqNo;
splitSequenceNo(m_combinedSeqNo);
m_adjLsaSeq += 10;
m_corLsaSeq += 10;
// Increment the adjacency LSA seq. no. if link-state or dry HR is enabled
if (hypState != HYPERBOLIC_STATE_ON) {
if (m_corLsaSeq != 0) {
_LOG_WARN("This router was previously configured for hyperbolic"
<< " routing without clearing the seq. no. file.");
m_corLsaSeq = 0;
}
m_adjLsaSeq += 10;
}
// Similarly, increment the coordinate LSA seq. no only if link-state is disabled.
if (hypState != HYPERBOLIC_STATE_OFF) {
if (m_adjLsaSeq != 0 &&
hypState == HYPERBOLIC_STATE_ON) {
_LOG_WARN("This router was previously configured for link-state"
<< " routing without clearing the seq. no. file.");
m_adjLsaSeq = 0;
}
m_corLsaSeq += 10;
}
m_nameLsaSeq += 10;
combineSequenceNo();
inputFile.close();
@@ -111,5 +130,3 @@ SequencingManager::writeLog() const
}
}//namespace nlsr
+5 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -28,7 +28,10 @@
#include <ndn-cxx/face.hpp>
#include "conf-parameter.hpp"
namespace nlsr {
class SequencingManager
{
public:
@@ -124,7 +127,7 @@ public:
writeSeqNoToFile() const;
void
initiateSeqNoFromFile();
initiateSeqNoFromFile(int hypState);
void
setSeqFileName(std::string filePath);
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -43,9 +43,9 @@ AdjacencyLsa::AdjacencyLsa(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
AdjacencyLsa::wireEncode(ndn::EncodingImpl<T>& block) const
AdjacencyLsa::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
@@ -63,10 +63,10 @@ AdjacencyLsa::wireEncode(ndn::EncodingImpl<T>& block) const
}
template size_t
AdjacencyLsa::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
AdjacencyLsa::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& encoder) const;
template size_t
AdjacencyLsa::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
AdjacencyLsa::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& encoder) const;
const ndn::Block&
AdjacencyLsa::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -109,9 +109,9 @@ public:
return *this;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+10 -12
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -43,32 +43,30 @@ Adjacency::Adjacency(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
Adjacency::wireEncode(ndn::EncodingImpl<T>& block) const
Adjacency::wireEncode(ndn::EncodingImpl<TAG>& encoder) const
{
size_t totalLength = 0;
totalLength += ndn::prependNonNegativeIntegerBlock(block,
ndn::tlv::nlsr::Cost,
m_cost);
totalLength += prependNonNegativeIntegerBlock(encoder, ndn::tlv::nlsr::Cost, m_cost);
totalLength += block.prependByteArrayBlock(
totalLength += encoder.prependByteArrayBlock(
ndn::tlv::nlsr::Uri, reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size());
totalLength += m_name.wireEncode(block);
totalLength += m_name.wireEncode(encoder);
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::Adjacency);
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::Adjacency);
return totalLength;
}
template size_t
Adjacency::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
Adjacency::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block) const;
template size_t
Adjacency::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
Adjacency::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block) const;
const ndn::Block&
Adjacency::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -101,9 +101,9 @@ public:
return *this;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -44,9 +44,9 @@ CoordinateLsa::CoordinateLsa(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
CoordinateLsa::wireEncode(ndn::EncodingImpl<T>& block) const
CoordinateLsa::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
size_t doubleLength = 10;
@@ -70,10 +70,10 @@ CoordinateLsa::wireEncode(ndn::EncodingImpl<T>& block) const
}
template size_t
CoordinateLsa::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
CoordinateLsa::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block) const;
template size_t
CoordinateLsa::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
CoordinateLsa::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block) const;
const ndn::Block&
CoordinateLsa::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -103,9 +103,9 @@ public:
return *this;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+14 -14
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -47,36 +47,36 @@ LsaInfo::LsaInfo(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
LsaInfo::wireEncode(ndn::EncodingImpl<T>& block) const
LsaInfo::wireEncode(ndn::EncodingImpl<TAG>& encoder) const
{
size_t totalLength = 0;
// Absence of an ExpirationPeriod signifies non-expiration
if (!m_hasInfiniteExpirationPeriod) {
totalLength += ndn::prependNonNegativeIntegerBlock(block,
ndn::tlv::nlsr::ExpirationPeriod,
m_expirationPeriod.count());
totalLength += prependNonNegativeIntegerBlock(encoder,
ndn::tlv::nlsr::ExpirationPeriod,
m_expirationPeriod.count());
}
totalLength += ndn::prependNonNegativeIntegerBlock(block,
ndn::tlv::nlsr::SequenceNumber,
m_sequenceNumber);
totalLength += prependNonNegativeIntegerBlock(encoder,
ndn::tlv::nlsr::SequenceNumber,
m_sequenceNumber);
totalLength += ndn::prependNestedBlock(block, ndn::tlv::nlsr::OriginRouter, m_originRouter);
totalLength += prependNestedBlock(encoder, ndn::tlv::nlsr::OriginRouter, m_originRouter);
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::LsaInfo);
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::LsaInfo);
return totalLength;
}
template size_t
LsaInfo::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
LsaInfo::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block) const;
template size_t
LsaInfo::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
LsaInfo::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block) const;
const ndn::Block&
LsaInfo::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -114,9 +114,9 @@ public:
return m_hasInfiniteExpirationPeriod;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -45,9 +45,9 @@ LsdbStatus::LsdbStatus(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
LsdbStatus::wireEncode(ndn::EncodingImpl<T>& block) const
LsdbStatus::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
@@ -73,10 +73,10 @@ LsdbStatus::wireEncode(ndn::EncodingImpl<T>& block) const
}
template size_t
LsdbStatus::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
LsdbStatus::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block) const;
template size_t
LsdbStatus::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
LsdbStatus::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block) const;
const ndn::Block&
LsdbStatus::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -156,9 +156,9 @@ public:
return m_hasNameLsas;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -43,9 +43,9 @@ NameLsa::NameLsa(const ndn::Block& block)
wireDecode(block);
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
NameLsa::wireEncode(ndn::EncodingImpl<T>& block) const
NameLsa::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
@@ -63,10 +63,10 @@ NameLsa::wireEncode(ndn::EncodingImpl<T>& block) const
}
template size_t
NameLsa::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
NameLsa::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block) const;
template size_t
NameLsa::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
NameLsa::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block) const;
const ndn::Block&
NameLsa::wireEncode() const
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -108,9 +108,9 @@ public:
return *this;
}
template<bool T>
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<T>& block) const;
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+21 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -51,6 +51,7 @@ PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::Face& face,
, m_sync(sync)
, m_keyChain(keyChain)
, m_validator(m_face, broadcastPrefix, certificateCache, certStore)
, m_isEnabled(false)
, COMMAND_PREFIX(ndn::Name(Nlsr::LOCALHOST_PREFIX).append(MODULE_COMPONENT))
{
}
@@ -68,6 +69,11 @@ PrefixUpdateProcessor::onInterest(const ndn::Interest& request)
{
_LOG_TRACE("Received Interest: " << request);
if (!m_isEnabled) {
sendNack(request);
return;
}
m_validator.validate(request,
bind(&PrefixUpdateProcessor::onCommandValidated, this, _1),
bind(&PrefixUpdateProcessor::onCommandValidationFailed, this, _1, _2));
@@ -185,6 +191,19 @@ PrefixUpdateProcessor::validateParameters(const ndn::nfd::ControlCommand& comman
return true;
}
void
PrefixUpdateProcessor::sendNack(const ndn::Interest& request)
{
ndn::MetaInfo metaInfo;
metaInfo.setType(ndn::tlv::ContentType_Nack);
shared_ptr<ndn::Data> responseData = std::make_shared<ndn::Data>(request.getName());
responseData->setMetaInfo(metaInfo);
m_keyChain.sign(*responseData);
m_face.put(*responseData);
}
void
PrefixUpdateProcessor::sendResponse(const std::shared_ptr<const ndn::Interest>& request,
uint32_t code,
@@ -197,7 +216,7 @@ PrefixUpdateProcessor::sendResponse(const std::shared_ptr<const ndn::Interest>&
ndn::nfd::ControlResponse response(code, text);
const ndn::Block& encodedControl = response.wireEncode();
std::shared_ptr<ndn::Data> responseData = ndn::make_shared<ndn::Data>(request->getName());
std::shared_ptr<ndn::Data> responseData = std::make_shared<ndn::Data>(request->getName());
responseData->setContent(encodedControl);
m_keyChain.sign(*responseData);
+11 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -78,10 +78,19 @@ public:
void
startListening();
void
enable()
{
m_isEnabled = true;
}
private:
void
onInterest(const ndn::Interest& request);
void
sendNack(const ndn::Interest& request);
void
sendResponse(const std::shared_ptr<const ndn::Interest>& request,
uint32_t code,
@@ -128,6 +137,7 @@ private:
SyncLogicHandler& m_sync;
ndn::KeyChain& m_keyChain;
Validator m_validator;
bool m_isEnabled;
const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
-116
View File
@@ -1,116 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
**/
#ifndef NLSR_TEST_DUMMY_FACE_HPP
#define NLSR_TEST_DUMMY_FACE_HPP
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/transport/transport.hpp>
namespace ndn {
class DummyTransport : public Transport
{
public:
void
receive(const Block& block)
{
m_receiveCallback(block);
}
virtual void
close()
{
}
virtual void
pause()
{
}
virtual void
resume()
{
}
virtual void
send(const Block& wire)
{
if (wire.type() == tlv::Interest) {
m_sentInterests->push_back(Interest(wire));
}
else if (wire.type() == tlv::Data) {
m_sentDatas->push_back(Data(wire));
}
}
virtual void
send(const Block& header, const Block& payload)
{
this->send(payload);
}
public:
std::vector<Interest>* m_sentInterests;
std::vector<Data>* m_sentDatas;
};
/** \brief a Face for unit testing
*/
class DummyFace : public Face
{
public:
explicit
DummyFace(shared_ptr<DummyTransport> transport)
: Face(transport)
, m_transport(transport)
{
m_transport->m_sentInterests = &m_sentInterests;
m_transport->m_sentDatas = &m_sentDatas;
}
/** \brief cause the Face to receive a packet
*/
template<typename Packet>
void
receive(const Packet& packet)
{
m_transport->receive(packet.wireEncode());
}
public:
std::vector<Interest> m_sentInterests;
std::vector<Data> m_sentDatas;
private:
shared_ptr<DummyTransport> m_transport;
};
inline shared_ptr<DummyFace>
makeDummyFace()
{
return make_shared<DummyFace>(make_shared<DummyTransport>());
}
} // namespace ndn
#endif // NLSR_TEST_DUMMY_FACE_HPP
+3
View File
@@ -95,5 +95,8 @@ private:
};
BOOST_GLOBAL_FIXTURE(IdentityFixture)
#if BOOST_VERSION >= 105900
;
#endif // BOOST_VERSION >= 105900
} // namespace nlsr
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -33,7 +33,7 @@ class PublisherFixture : public BaseFixture
{
public:
PublisherFixture()
: face(ndn::util::makeDummyClientFace())
: face(make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, lsdb(nlsr, g_scheduler, nlsr.getSyncLogicHandler())
{
@@ -83,10 +83,10 @@ public:
CoordinateLsa
createCoordinateLsa(const std::string& origin, double radius, double angle)
{
CoordinateLsa lsa(origin, CoordinateLsa::TYPE_STRING, 1, ndn::time::system_clock::now(),
CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
radius, angle);
return std::move(lsa);
return lsa;
}
void
+7 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -59,8 +59,8 @@ BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic)
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
ndn::Block parser = face->sentDatas[0].getContent();
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterB LSA
@@ -93,8 +93,8 @@ BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
ndn::Block parser = face->sentDatas[0].getContent();
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterC LSA
@@ -136,8 +136,8 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic)
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
ndn::Block parser = face->sentDatas[0].getContent();
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterB LSA
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -36,8 +36,8 @@ processDatasetInterest(shared_ptr<ndn::util::DummyClientFace> face,
{
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
ndn::Block parser(face->sentDatas[0].getContent());
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser(face->sentData[0].getContent());
parser.parse();
ndn::Block::element_const_iterator it = parser.elements_begin();
@@ -46,18 +46,18 @@ processDatasetInterest(shared_ptr<ndn::util::DummyClientFace> face,
BOOST_CHECK(it == parser.elements_end());
face->sentDatas.clear();
face->sentData.clear();
}
void
checkErrorResponse(shared_ptr<ndn::util::DummyClientFace> face, uint64_t expectedCode)
{
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::nfd::ControlResponse response(face->sentDatas[0].getContent().blockFromValue());
ndn::nfd::ControlResponse response(face->sentData[0].getContent().blockFromValue());
BOOST_CHECK_EQUAL(response.getCode(), expectedCode);
face->sentDatas.clear();
face->sentData.clear();
}
BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
@@ -81,7 +81,9 @@ BOOST_AUTO_TEST_CASE(Basic)
lsdb.installNameLsa(nameLsa);
ndn::Name thisRouter("/This/Router");
LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
publisher.setRouterNameCommandPrefix(thisRouter);
publisher.startListeningOnLocalhost();
face->processEvents(ndn::time::milliseconds(10));
@@ -136,7 +138,8 @@ BOOST_AUTO_TEST_CASE(Basic)
BOOST_AUTO_TEST_CASE(InvalidCommand)
{
ndn::Name thisRouter("/This/Router");
LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
publisher.setRouterNameCommandPrefix(thisRouter);
// Localhost prefix
publisher.startListeningOnLocalhost();
@@ -179,7 +182,7 @@ BOOST_AUTO_TEST_CASE(InvalidCommand)
face->receive(ndn::Interest(ndn::Name(thisRouter).append("malformed")));
face->processEvents(ndn::time::milliseconds(1));
BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
BOOST_CHECK_EQUAL(face->sentData.size(), 0);
}
BOOST_AUTO_TEST_SUITE_END()
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -90,9 +90,9 @@ BOOST_AUTO_TEST_CASE(Basic)
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentDatas[0].getContent();
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
ndn::Block::element_const_iterator it = parser.elements_begin();
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -74,7 +74,7 @@ protected:
size_t totalLength = 0;
for (int64_t i = 0; i < N; i++)
{
totalLength += ndn::prependNonNegativeIntegerBlock(outBuffer, ndn::tlv::Content, i);
totalLength += prependNonNegativeIntegerBlock(outBuffer, ndn::tlv::Content, i);
}
m_totalPayloadLength += totalLength;
return totalLength;
@@ -89,7 +89,7 @@ class SegmentPublisherFixture
{
public:
SegmentPublisherFixture()
: m_face(ndn::util::makeDummyClientFace())
: m_face(std::make_shared<ndn::util::DummyClientFace>())
, m_expectedFreshnessPeriod(ndn::time::milliseconds(111))
, m_publisher(*m_face, m_keyChain, m_expectedFreshnessPeriod)
, m_publishingPrefix("/localhost/nfd/SegmentPublisherFixture")
@@ -158,8 +158,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(Generate, T, DatasetSizes, SegmentPublisherFixt
nSegments == 0)
++nSegments;
BOOST_CHECK_EQUAL(this->m_face->sentDatas.size(), nSegments);
for (const ndn::Data& data : this->m_face->sentDatas) {
BOOST_CHECK_EQUAL(this->m_face->sentData.size(), nSegments);
for (const ndn::Data& data : this->m_face->sentData) {
this->validate(data);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+69 -10
View File
@@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,23 +17,23 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author Ashlesh Gawande <agawande@memphis.edu>
*
**/
#include "adjacency-list.hpp"
#include "adjacent.hpp"
#include "conf-parameter.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
using namespace std;
BOOST_AUTO_TEST_SUITE(TestAdjacenctList)
BOOST_AUTO_TEST_SUITE(TestAdjacencyList)
BOOST_AUTO_TEST_CASE(AdjacenctListBasic)
BOOST_AUTO_TEST_CASE(Basic)
{
const string ADJ_NAME_1 = "testname";
const string ADJ_NAME_2 = "testname2";
@@ -63,7 +64,65 @@ BOOST_AUTO_TEST_CASE(AdjacenctListBasic)
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE);
}
BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive)
{
Adjacent adjacencyA("/router/A");
Adjacent adjacencyB("/router/B");
adjacencyA.setStatus(Adjacent::STATUS_ACTIVE);
adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
AdjacencyList adjacencies;
adjacencies.insert(adjacencyA);
adjacencies.insert(adjacencyB);
ConfParameter conf;
BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
}
BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut)
{
Adjacent adjacencyA("/router/A");
Adjacent adjacencyB("/router/B");
adjacencyA.setStatus(Adjacent::STATUS_INACTIVE);
adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
AdjacencyList adjacencies;
adjacencies.insert(adjacencyA);
adjacencies.insert(adjacencyB);
ConfParameter conf;
conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
}
BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable)
{
Adjacent adjacencyA("/router/A");
Adjacent adjacencyB("/router/B");
adjacencyA.setStatus(Adjacent::STATUS_INACTIVE);
adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
adjacencyB.setInterestTimedOutNo(0);
AdjacencyList adjacencies;
adjacencies.insert(adjacencyA);
adjacencies.insert(adjacencyB);
ConfParameter conf;
conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace tests
} //namespace nlsr
} // namespace tests
} // namespace nlsr
+22 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -20,7 +20,6 @@
**/
#include "test-common.hpp"
#include "dummy-face.hpp"
#include "logger.hpp"
#include <fstream>
@@ -31,10 +30,11 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
const std::string SECTION_GENERAL =
@@ -132,7 +132,7 @@ class ConfFileProcessorFixture : public BaseFixture
{
public:
ConfFileProcessorFixture()
: face(ndn::makeDummyFace())
: face(make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, CONFIG_FILE("unit-test-nlsr.conf")
, m_logConfigFileName(boost::filesystem::unique_path().native())
@@ -200,7 +200,7 @@ public:
}
public:
shared_ptr<ndn::DummyFace> face;
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
private:
@@ -518,6 +518,23 @@ BOOST_AUTO_TEST_CASE(LoadCertToPublish)
boost::filesystem::remove(CERT_PATH);
}
BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
{
const std::string SECTION_SECURITY =
"security\n"
"{\n"
" validator\n"
" {\n"
" trust-anchor\n"
" {\n"
" type any\n"
" }\n"
" }\n"
"}\n\n";
BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
+1 -1
View File
@@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
BOOST_CHECK_EQUAL(cp1.getRouterPrefix(), "/ATT/memphis/router1");
BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), (uint32_t)2);
BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), 2);
BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);
+5 -5
View File
@@ -21,25 +21,25 @@
#include "test-common.hpp"
#include "control-commands.hpp"
#include "dummy-face.hpp"
#include "route/fib.hpp"
#include "adjacency-list.hpp"
#include "conf-parameter.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
class FibFixture : public BaseFixture
{
public:
FibFixture()
: face(ndn::makeDummyFace())
, interests(face->m_sentInterests)
: face(make_shared<ndn::util::DummyClientFace>())
, interests(face->sentInterests)
{
INIT_LOGGERS("/tmp", "DEBUG");
@@ -63,7 +63,7 @@ public:
}
public:
shared_ptr<ndn::DummyFace> face;
shared_ptr<ndn::util::DummyClientFace> face;
ndn::KeyChain keyChain;
shared_ptr<Fib> fib;
+11 -11
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -20,7 +20,6 @@
**/
#include "test-common.hpp"
#include "dummy-face.hpp"
#include "route/routing-table-calculator.hpp"
@@ -33,10 +32,11 @@
#include <boost/test/unit_test.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
using ndn::time::system_clock;
static const system_clock::TimePoint MAX_TIME = system_clock::TimePoint::max();
@@ -45,7 +45,7 @@ class HyperbolicCalculatorFixture : public BaseFixture
{
public:
HyperbolicCalculatorFixture()
: face(ndn::makeDummyFace())
: face(make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, routingTable(nlsr.getRoutingTable())
, adjacencies(nlsr.getAdjacencyList())
@@ -67,10 +67,10 @@ public:
adjacencies.insert(b);
adjacencies.insert(c);
AdjLsa adjA(a.getName(), AdjLsa::TYPE_STRING, 1, MAX_TIME, 2, adjacencies);
AdjLsa adjA(a.getName(), 1, MAX_TIME, 2, adjacencies);
lsdb.installAdjLsa(adjA);
CoordinateLsa coordA(adjA.getOrigRouter(), CoordinateLsa::TYPE_STRING, 1, MAX_TIME, 16.23, 2.97);
CoordinateLsa coordA(adjA.getOrigRouter(), 1, MAX_TIME, 16.23, 2.97);
lsdb.installCoordinateLsa(coordA);
// Router B
@@ -81,10 +81,10 @@ public:
adjacencyListB.insert(a);
adjacencyListB.insert(c);
AdjLsa adjB(b.getName(), AdjLsa::TYPE_STRING, 1, MAX_TIME, 2, adjacencyListB);
AdjLsa adjB(b.getName(), 1, MAX_TIME, 2, adjacencyListB);
lsdb.installAdjLsa(adjB);
CoordinateLsa coordB(adjB.getOrigRouter(), CoordinateLsa::TYPE_STRING, 1, MAX_TIME, 16.59, 3.0);
CoordinateLsa coordB(adjB.getOrigRouter(), 1, MAX_TIME, 16.59, 3.0);
lsdb.installCoordinateLsa(coordB);
// Router C
@@ -95,17 +95,17 @@ public:
adjacencyListC.insert(a);
adjacencyListC.insert(b);
AdjLsa adjC(c.getName(), AdjLsa::TYPE_STRING, 1, MAX_TIME, 2, adjacencyListC);
AdjLsa adjC(c.getName(), 1, MAX_TIME, 2, adjacencyListC);
lsdb.installAdjLsa(adjC);
CoordinateLsa coordC(adjC.getOrigRouter(), CoordinateLsa::TYPE_STRING, 1, MAX_TIME, 14.11, 2.99);
CoordinateLsa coordC(adjC.getOrigRouter(), 1, MAX_TIME, 14.11, 2.99);
lsdb.installCoordinateLsa(coordC);
map.createFromAdjLsdb(nlsr);
}
public:
shared_ptr<DummyFace> face;
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
Map map;
+268
View File
@@ -0,0 +1,268 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "route/routing-table-calculator.hpp"
#include "adjacency-list.hpp"
#include "lsa.hpp"
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "test-common.hpp"
#include "route/map.hpp"
#include "route/routing-table.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
static const ndn::time::system_clock::TimePoint MAX_TIME =
ndn::time::system_clock::TimePoint::max();
class LinkStateCalculatorFixture : public BaseFixture
{
public:
LinkStateCalculatorFixture()
: face(make_shared<ndn::util::DummyClientFace>(g_ioService))
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, routingTable(nlsr.getRoutingTable())
, lsdb(nlsr.getLsdb())
{
setUpTopology();
}
// Triangle topology with routers A, B, C connected
void setUpTopology()
{
INIT_LOGGERS("/tmp", "TRACE");
ConfParameter& conf = nlsr.getConfParameter();
conf.setNetwork("/ndn");
conf.setSiteName("/router");
conf.setRouterName("/a");
conf.buildRouterPrefix();
Adjacent a(ROUTER_A_NAME, ROUTER_A_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
Adjacent b(ROUTER_B_NAME, ROUTER_B_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
Adjacent c(ROUTER_C_NAME, ROUTER_C_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
// Router A
b.setLinkCost(LINK_AB_COST);
c.setLinkCost(LINK_AC_COST);
AdjacencyList& adjacencyListA = nlsr.getAdjacencyList();
adjacencyListA.insert(b);
adjacencyListA.insert(c);
AdjLsa adjA(a.getName(), 1, MAX_TIME, 2, adjacencyListA);
lsdb.installAdjLsa(adjA);
// Router B
a.setLinkCost(LINK_AB_COST);
c.setLinkCost(LINK_BC_COST);
AdjacencyList adjacencyListB;
adjacencyListB.insert(a);
adjacencyListB.insert(c);
AdjLsa adjB(b.getName(), 1, MAX_TIME, 2, adjacencyListB);
lsdb.installAdjLsa(adjB);
// Router C
a.setLinkCost(LINK_AC_COST);
b.setLinkCost(LINK_BC_COST);
AdjacencyList adjacencyListC;
adjacencyListC.insert(a);
adjacencyListC.insert(b);
AdjLsa adjC(c.getName(), 1, MAX_TIME, 2, adjacencyListC);
lsdb.installAdjLsa(adjC);
map.createFromAdjLsdb(nlsr);
}
public:
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
Map map;
RoutingTable& routingTable;
Lsdb& lsdb;
static const ndn::Name ROUTER_A_NAME;
static const ndn::Name ROUTER_B_NAME;
static const ndn::Name ROUTER_C_NAME;
static const std::string ROUTER_A_FACE;
static const std::string ROUTER_B_FACE;
static const std::string ROUTER_C_FACE;
static const double LINK_AB_COST;
static const double LINK_AC_COST;
static const double LINK_BC_COST;
};
const ndn::Name LinkStateCalculatorFixture::ROUTER_A_NAME = "/ndn/router/a";
const ndn::Name LinkStateCalculatorFixture::ROUTER_B_NAME = "/ndn/router/b";
const ndn::Name LinkStateCalculatorFixture::ROUTER_C_NAME = "/ndn/router/c";
const std::string LinkStateCalculatorFixture::ROUTER_A_FACE = "face-a";
const std::string LinkStateCalculatorFixture::ROUTER_B_FACE = "face-b";
const std::string LinkStateCalculatorFixture::ROUTER_C_FACE = "face-c";
const double LinkStateCalculatorFixture::LINK_AB_COST = 5;
const double LinkStateCalculatorFixture::LINK_AC_COST = 10;
const double LinkStateCalculatorFixture::LINK_BC_COST = 17;
BOOST_FIXTURE_TEST_SUITE(TestLinkStateRoutingCalculator, LinkStateCalculatorFixture)
BOOST_AUTO_TEST_CASE(Basic)
{
LinkStateRoutingTableCalculator calculator(map.getMapSize());
calculator.calculatePath(map, routingTable, nlsr);
RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME);
BOOST_REQUIRE(entryB != nullptr);
// Router A should be able to get to B through B and to B through C
NexthopList& bHopList = entryB->getNexthopList();
BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2);
for (const NextHop& hop : bHopList) {
std::string faceUri = hop.getConnectingFaceUri();
uint64_t cost = hop.getRouteCostAsAdjustedInteger();
BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == LINK_AB_COST) ||
(faceUri == ROUTER_C_FACE && cost == LINK_AC_COST + LINK_BC_COST));
}
RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME);
BOOST_REQUIRE(entryC != nullptr);
// Router A should be able to get to C through C and to C through B
NexthopList& cHopList = entryC->getNexthopList();
BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2);
for (const NextHop& hop : cHopList) {
std::string faceUri = hop.getConnectingFaceUri();
uint64_t cost = hop.getRouteCostAsAdjustedInteger();
BOOST_CHECK((faceUri == ROUTER_C_FACE && cost == LINK_AC_COST) ||
(faceUri == ROUTER_B_FACE && cost == LINK_AB_COST + LINK_BC_COST));
}
}
BOOST_AUTO_TEST_CASE(Asymmetric)
{
// Asymmetric link cost between B and C
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(AdjLsa::TYPE_STRING);
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
Adjacent* c = lsa->getAdl().findAdjacent(ROUTER_C_NAME);
BOOST_REQUIRE(c != nullptr);
double higherLinkCost = LINK_BC_COST + 1;
c->setLinkCost(higherLinkCost);
// Calculation should consider the link between B and C as having cost = higherLinkCost
LinkStateRoutingTableCalculator calculator(map.getMapSize());
calculator.calculatePath(map, routingTable, nlsr);
RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME);
BOOST_REQUIRE(entryB != nullptr);
// Router A should be able to get to B through B and to B through C
NexthopList& bHopList = entryB->getNexthopList();
BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2);
for (const NextHop& hop : bHopList) {
std::string faceUri = hop.getConnectingFaceUri();
uint64_t cost = hop.getRouteCostAsAdjustedInteger();
BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == LINK_AB_COST) ||
(faceUri == ROUTER_C_FACE && cost == LINK_AC_COST + higherLinkCost));
}
RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME);
BOOST_REQUIRE(entryC != nullptr);
// Router A should be able to get to C through C and to C through B
NexthopList& cHopList = entryC->getNexthopList();
BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2);
for (const NextHop& hop : cHopList) {
std::string faceUri = hop.getConnectingFaceUri();
uint64_t cost = hop.getRouteCostAsAdjustedInteger();
BOOST_CHECK((faceUri == ROUTER_C_FACE && cost == LINK_AC_COST) ||
(faceUri == ROUTER_B_FACE && cost == LINK_AB_COST + higherLinkCost));
}
}
BOOST_AUTO_TEST_CASE(AsymmetricZeroCost)
{
// Asymmetric link cost between B and C
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(AdjLsa::TYPE_STRING);
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
Adjacent* c = lsa->getAdl().findAdjacent(ROUTER_C_NAME);
BOOST_REQUIRE(c != nullptr);
c->setLinkCost(0);
// Calculation should consider the link between B and C as down
LinkStateRoutingTableCalculator calculator(map.getMapSize());
calculator.calculatePath(map, routingTable, nlsr);
// Router A should be able to get to B through B but not through C
RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME);
BOOST_REQUIRE(entryB != nullptr);
NexthopList& bHopList = entryB->getNexthopList();
BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 1);
NextHop& nextHopForB = bHopList.getNextHops().front();
BOOST_CHECK(nextHopForB.getConnectingFaceUri() == ROUTER_B_FACE &&
nextHopForB.getRouteCostAsAdjustedInteger() == LINK_AB_COST);
// Router A should be able to get to C through C but not through B
RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME);
BOOST_REQUIRE(entryC != nullptr);
NexthopList& cHopList = entryC->getNexthopList();
BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 1);
NextHop& nextHopForC = cHopList.getNextHops().front();
BOOST_CHECK(nextHopForC.getConnectingFaceUri() == ROUTER_C_FACE &&
nextHopForC.getRouteCostAsAdjustedInteger() == LINK_AC_COST);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+143 -26
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -19,14 +19,19 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "test-common.hpp"
#include "adjacent.hpp"
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
#include <boost/test/unit_test.hpp>
#include <ndn-cxx/util/time.hpp>
#include <sstream>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestLsa)
BOOST_AUTO_TEST_CASE(NameLsaBasic)
@@ -39,9 +44,10 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic)
npl1.insert(s1);
npl1.insert(s2);
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
//lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12.
NameLsa nlsa1("router1", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
NameLsa nlsa2("router2", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
//3rd arg is seqNo. which will be a random number I just put in 12.
NameLsa nlsa1("router1", 12, testTimePoint, npl1);
NameLsa nlsa2("router2", 12, testTimePoint, npl1);
BOOST_CHECK_EQUAL(nlsa1.getLsType(), NameLsa::TYPE_STRING);
@@ -52,36 +58,50 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic)
BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
{
Adjacent adj1("adjacent");
Adjacent adj2("adjacent2");
AdjacencyList adjList;
adjList.insert(adj1);
ndn::Name routerName("/ndn/site/router");
ndn::Name adjacencyName("/ndn/site/adjacency");
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
//For AdjLsa, lsType is 2.
//1 is the number of adjacent in adjacent list.
AdjLsa alsa1("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
AdjLsa alsa2("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
uint32_t seqNo = 12;
// An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies
AdjacencyList activeAdjacencies;
Adjacent activeAdjacency(adjacencyName);
activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE);
activeAdjacencies.insert(activeAdjacency);
AdjLsa alsa1(routerName, seqNo, testTimePoint,
activeAdjacencies.getSize(), activeAdjacencies);
BOOST_CHECK_EQUAL(alsa1.getAdl().getSize(), 1);
BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING);
BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), seqNo);
BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
BOOST_CHECK(alsa1.isEqualContent(alsa2));
// An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies
AdjacencyList inactiveAdjacencies;
Adjacent inactiveAdjacency(adjacencyName);
inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE);
inactiveAdjacencies.insert(inactiveAdjacency);
alsa1.addAdjacent(adj2);
AdjLsa alsa2(routerName, seqNo, testTimePoint,
inactiveAdjacencies.getSize(), inactiveAdjacencies);
BOOST_CHECK_EQUAL(alsa2.getAdl().getSize(), 0);
const std::string ADJACENT_1 = "adjacent2";
BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
// Thus, the two LSAs should not have equal content
BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false);
// Create a duplicate of alsa1 which should have equal content
AdjLsa alsa3(routerName, seqNo, testTimePoint,
activeAdjacencies.getSize(), activeAdjacencies);
BOOST_CHECK(alsa1.isEqualContent(alsa3));
}
BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
{
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
//For CoordinateLsa, lsType is 3.
CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, 30.0);
CoordinateLsa clsa2("router1", 12, testTimePoint, 2.5, 30.0);
BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
@@ -91,7 +111,104 @@ BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
}
BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
{
Adjacent adj1("adjacent1");
Adjacent adj2("adjacent2");
adj1.setStatus(Adjacent::STATUS_ACTIVE);
adj2.setStatus(Adjacent::STATUS_ACTIVE);
AdjacencyList adjList;
adjList.insert(adj1);
adjList.insert(adj2);
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
std::ostringstream ss;
ss << testTimePoint;
const std::string TEST_TIME_POINT_STRING = ss.str();
AdjLsa lsa("router1", 12, testTimePoint, adjList.getSize(), adjList);
std::string EXPECTED_OUTPUT =
"Adj Lsa:\n"
" Origination Router: /router1\n"
" Ls Type: adjacency\n"
" Ls Seq No: 12\n"
" Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n"
" Adjacents: \n"
" Adjacent 1:\n"
" Adjacent Name: /adjacent1\n"
" Connecting FaceUri: \n"
" Link Cost: 10\n"
" Adjacent 2:\n"
" Adjacent Name: /adjacent2\n"
" Connecting FaceUri: \n"
" Link Cost: 10\n"
"adj_lsa_end";
std::ostringstream os;
os << lsa;
BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
}
BOOST_AUTO_TEST_CASE(TestInitializeFromContent)
{
//Adj LSA
Adjacent adj1("adjacent1");
Adjacent adj2("adjacent2");
adj1.setStatus(Adjacent::STATUS_ACTIVE);
adj2.setStatus(Adjacent::STATUS_ACTIVE);
//If we don't do this the test will fail
//Adjacent has default cost of 10 but no default
//connecting face URI, so initializeFromContent fails
adj1.setConnectingFaceUri("10.0.0.1");
adj2.setConnectingFaceUri("10.0.0.2");
AdjacencyList adjList;
adjList.insert(adj1);
adjList.insert(adj2);
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.getSize(), adjList);
AdjLsa adjlsa2;
BOOST_CHECK(adjlsa2.initializeFromContent(adjlsa1.getData()));
BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
//Name LSA
NamePrefixList npl1;
std::string s1 = "name1";
std::string s2 = "name2";
npl1.insert(s1);
npl1.insert(s2);
NameLsa nlsa1("router1", 1, testTimePoint, npl1);
NameLsa nlsa2;
BOOST_CHECK(nlsa2.initializeFromContent(nlsa1.getData()));
BOOST_CHECK_EQUAL(nlsa1.getData(), nlsa2.getData());
//Coordinate LSA
CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, 30.0);
CoordinateLsa clsa2;
BOOST_CHECK(clsa2.initializeFromContent(clsa1.getData()));
BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
} // namespace test
} // namespace nlsr
+86 -16
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -20,7 +20,6 @@
**/
#include "test-common.hpp"
#include "dummy-face.hpp"
#include "lsdb.hpp"
#include "nlsr.hpp"
@@ -28,17 +27,19 @@
#include "name-prefix-list.hpp"
#include <boost/test/unit_test.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
#include <ndn-cxx/util/segment-fetcher.hpp>
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
class LsdbFixture : public BaseFixture
{
public:
LsdbFixture()
: face(ndn::makeDummyFace())
: face(make_shared<ndn::util::DummyClientFace>(g_ioService))
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, sync(*face, nlsr.getLsdb(), nlsr.getConfParameter(), nlsr.getSequencingManager())
, lsdb(nlsr.getLsdb())
@@ -53,7 +54,7 @@ public:
nlsr.initialize();
face->processEvents(ndn::time::milliseconds(1));
face->m_sentInterests.clear();
face->sentInterests.clear();
INIT_LOGGERS("/tmp", "DEBUG");
}
@@ -89,7 +90,7 @@ public:
}
public:
shared_ptr<DummyFace> face;
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
SyncLogicHandler sync;
@@ -113,7 +114,7 @@ BOOST_AUTO_TEST_CASE(LsdbSync)
lsdb.expressInterest(oldInterestName, 0);
face->processEvents(ndn::time::milliseconds(1));
std::vector<ndn::Interest>& interests = face->m_sentInterests;
std::vector<ndn::Interest>& interests = face->sentInterests;
BOOST_REQUIRE(interests.size() > 0);
std::vector<ndn::Interest>::iterator it = interests.begin();
@@ -122,10 +123,11 @@ BOOST_AUTO_TEST_CASE(LsdbSync)
interests.clear();
steady_clock::TimePoint deadline = steady_clock::now() +
ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
ndn::time::seconds(LSA_REFRESH_TIME_MAX);
// Simulate an LSA interest timeout
lsdb.processInterestTimedOut(oldInterestName, 0, deadline, interestName, oldSeqNo);
lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
oldInterestName, 0, deadline, interestName, oldSeqNo);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE(interests.size() > 0);
@@ -149,13 +151,81 @@ BOOST_AUTO_TEST_CASE(LsdbSync)
interests.clear();
// Simulate an LSA interest timeout where the sequence number is outdated
lsdb.processInterestTimedOut(oldInterestName, 0, deadline, interestName, oldSeqNo);
lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
oldInterestName, 0, deadline, interestName, oldSeqNo);
face->processEvents(ndn::time::milliseconds(1));
// Interest should not be expressed for outdated sequence number
BOOST_CHECK_EQUAL(interests.size(), 0);
}
BOOST_AUTO_TEST_CASE(SegmentLsaData)
{
ndn::Name router("/ndn/cs/%C1.Router/router1");
uint64_t seqNo = 12;
NamePrefixList prefixList;
NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
int nPrefixes = 0;
while (lsa.getData().size() < ndn::MAX_NDN_PACKET_SIZE) {
lsa.addName(ndn::Name(prefix).appendNumber(++nPrefixes));
}
std::string expectedDataContent = lsa.getData();
lsdb.installNameLsa(lsa);
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
interestName.appendNumber(seqNo);
ndn::Interest interest(interestName);
lsdb.processInterest(ndn::Name(), interest);
face->processEvents(ndn::time::milliseconds(1));
std::vector<ndn::Data> data = face->sentData;
std::string recvDataContent;
for (unsigned int i = 0; i < data.size(); ++i)
{
const ndn::Block& nameBlock = data[i].getContent();
std::string nameBlockContent(reinterpret_cast<char const*>(nameBlock.value()),
nameBlock.value_size());
recvDataContent += nameBlockContent;
}
BOOST_CHECK_EQUAL(expectedDataContent, recvDataContent);
}
BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
{
ndn::Name router("/ndn/cs/%C1.Router/router1");
uint64_t seqNo = 12;
NamePrefixList prefixList;
NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
ndn::Name prefix("/prefix/");
for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
}
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
interestName.appendNumber(seqNo);
const ndn::ConstBufferPtr bufferPtr = make_shared<ndn::Buffer>(lsa.getData().c_str(),
lsa.getData().size());
lsdb.afterFetchLsa(bufferPtr, interestName);
NameLsa* foundLsa = lsdb.findNameLsa(lsa.getKey());
BOOST_REQUIRE(foundLsa != nullptr);
BOOST_CHECK_EQUAL(foundLsa->getData(), lsa.getData());
}
BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
{
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
@@ -171,7 +241,7 @@ BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
//For NameLsa lsType is name.
//12 is seqNo, randomly generated.
//1800 is the default life time.
NameLsa nlsa1(ndn::Name("/router1/1"), NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
NameLsa nlsa1(ndn::Name("/router1/1"), 12, testTimePoint, npl1);
Lsdb lsdb1(nlsr, g_scheduler, nlsr.getSyncLogicHandler());
@@ -198,7 +268,7 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
std::string otherRouter("/ndn/site/%C1.router/other-router");
ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
NameLsa lsa(otherRouter, NameLsa::TYPE_STRING, 1, MAX_TIME, prefixes);
NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
lsdb.installNameLsa(lsa);
BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter + "/name", NameLsa::TYPE_STRING), true);
@@ -210,7 +280,7 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
ndn::Name name3("/ndn/name3");
prefixes.insert(name3);
NameLsa addLsa(otherRouter, NameLsa::TYPE_STRING, 2, MAX_TIME, prefixes);
NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
lsdb.installNameLsa(addLsa);
// Lsa should include name1, name2, and name3
@@ -219,7 +289,7 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
// Remove a prefix: name2
prefixes.remove(name2);
NameLsa removeLsa(otherRouter, NameLsa::TYPE_STRING, 3, MAX_TIME, prefixes);
NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
lsdb.installNameLsa(removeLsa);
// Lsa should include name1 and name3
@@ -229,7 +299,7 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
prefixes.insert(name2);
prefixes.remove(name3);
NameLsa addAndRemoveLsa(otherRouter, NameLsa::TYPE_STRING, 4, MAX_TIME, prefixes);
NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
lsdb.installNameLsa(addAndRemoveLsa);
// Lsa should include name1 and name2
@@ -243,7 +313,7 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
newPrefixes.insert(name4);
newPrefixes.insert(name5);
NameLsa newLsa(otherRouter, NameLsa::TYPE_STRING, 5, MAX_TIME, newPrefixes);
NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
lsdb.installNameLsa(newLsa);
// Lsa should include name4 and name5
+138
View File
@@ -0,0 +1,138 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "nlsr.hpp"
#include "test-common.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
class NamePrefixTableFixture : public UnitTestTimeFixture
{
public:
NamePrefixTableFixture()
: face(make_shared<ndn::util::DummyClientFace>(g_ioService))
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, lsdb(nlsr.getLsdb())
, npt(nlsr.getNamePrefixTable())
{
INIT_LOGGERS("/tmp", "DEBUG");
}
public:
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
Lsdb& lsdb;
NamePrefixTable& npt;
};
BOOST_AUTO_TEST_SUITE(TestNamePrefixTable)
BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
{
ConfParameter& conf = nlsr.getConfParameter();
conf.setNetwork("/ndn");
conf.setSiteName("/router");
conf.setRouterName("/a");
conf.buildRouterPrefix();
RoutingTable& routingTable = nlsr.getRoutingTable();
routingTable.setRoutingCalcInterval(0);
NamePrefixTable& npt = nlsr.getNamePrefixTable();
Adjacent thisRouter(conf.getRouterPrefix(), "udp://face", 0, Adjacent::STATUS_ACTIVE, 0, 0);
ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub");
Adjacent bupt(buptRouterName, "udp://bupt", 0, Adjacent::STATUS_ACTIVE, 0, 0);
// This router's Adjacency LSA
nlsr.getAdjacencyList().insert(bupt);
AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1,
ndn::time::system_clock::now() + ndn::time::seconds::max(),
2,
nlsr.getAdjacencyList());
lsdb.installAdjLsa(thisRouterAdjLsa);
// BUPT Adjacency LSA
AdjacencyList buptAdjacencies;
buptAdjacencies.insert(thisRouter);
AdjLsa buptAdjLsa(buptRouterName, 1,
ndn::time::system_clock::now() + ndn::time::seconds(5),
0 , buptAdjacencies);
lsdb.installAdjLsa(buptAdjLsa);
// BUPT Name LSA
ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt");
NamePrefixList buptNames;
buptNames.insert(buptAdvertisedName);
NameLsa buptNameLsa(buptRouterName, 1, ndn::time::system_clock::now(),
buptNames);
lsdb.installNameLsa(buptNameLsa);
// Advance clocks to expire LSAs
this->advanceClocks(ndn::time::seconds(15));
// LSA expirations should cause NPT entries to be completely removed
NamePrefixTable::const_iterator it = npt.begin();
BOOST_REQUIRE(it == npt.end());
// Install new name LSA
NameLsa buptNewNameLsa(buptRouterName, 12,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
buptNames);
lsdb.installNameLsa(buptNewNameLsa);
this->advanceClocks(ndn::time::seconds(1));
// Install new adjacency LSA
AdjLsa buptNewAdjLsa(buptRouterName, 12,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
0, buptAdjacencies);
lsdb.installAdjLsa(buptNewAdjLsa);
this->advanceClocks(ndn::time::seconds(1));
// Each NPT entry should have a destination router
it = npt.begin();
BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptRouterName);
BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1);
BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName);
++it;
BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptAdvertisedName);
BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1);
BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace nlsr
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+165 -30
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -21,7 +21,6 @@
#include "test-common.hpp"
#include "control-commands.hpp"
#include "dummy-face.hpp"
#include "nlsr.hpp"
@@ -31,19 +30,42 @@
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
BOOST_FIXTURE_TEST_SUITE(TestNlsr, BaseFixture)
class NlsrFixture : public UnitTestTimeFixture
{
public:
NlsrFixture()
: face(make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, lsdb(nlsr.getLsdb())
, neighbors(nlsr.getAdjacencyList())
{
}
void
receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver)
{
ndn::Name dataName(sender);
dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion();
shared_ptr<ndn::Data> data = make_shared<ndn::Data>(dataName);
nlsr.m_helloProtocol.onContentValidated(data);
}
public:
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
Lsdb& lsdb;
AdjacencyList& neighbors;
};
BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
{
shared_ptr<DummyFace> face = ndn::makeDummyFace();
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
// Simulate loading configuration file
AdjacencyList& neighbors = nlsr.getAdjacencyList();
Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
@@ -65,12 +87,7 @@ BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
{
shared_ptr<DummyFace> face = ndn::makeDummyFace();
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
// Simulate loading configuration file
AdjacencyList& neighbors = nlsr.getAdjacencyList();
Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
@@ -90,9 +107,6 @@ BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
BOOST_AUTO_TEST_CASE(SetEventIntervals)
{
shared_ptr<DummyFace> face = ndn::makeDummyFace();
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
// Simulate loading configuration file
ConfParameter& conf = nlsr.getConfParameter();
conf.setAdjLsaBuildInterval(3);
@@ -111,8 +125,9 @@ BOOST_AUTO_TEST_CASE(SetEventIntervals)
BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
{
shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace(g_ioService);
shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>(g_ioService);
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
Lsdb& lsdb = nlsr.getLsdb();
// Simulate loading configuration file
ConfParameter& conf = nlsr.getConfParameter();
@@ -124,7 +139,6 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
// Add active neighbors
AdjacencyList& neighbors = nlsr.getAdjacencyList();
uint64_t destroyFaceId = 128;
// Create a neighbor whose Face will be destroyed
@@ -133,23 +147,49 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
neighbors.insert(failNeighbor);
// Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Adjacent otherNeighbor("/ndn/neighborB", "uri://faceB", 25, Adjacent::STATUS_ACTIVE, 0, 256);
Adjacent otherNeighbor("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_ACTIVE, 0, 256);
neighbors.insert(otherNeighbor);
nlsr.initialize();
// Simulate successful HELLO responses
nlsr.getLsdb().scheduleAdjLsaBuild();
lsdb.scheduleAdjLsaBuild();
// Set up adjacency LSAs
// This router
Adjacent thisRouter(conf.getRouterPrefix(), "uri://faceB", 10, Adjacent::STATUS_ACTIVE, 0, 256);
AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors);
lsdb.installAdjLsa(ownAdjLsa);
// Router that will fail
AdjacencyList failAdjacencies;
failAdjacencies.insert(thisRouter);
AdjLsa failAdjLsa("/ndn/neighborA", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, failAdjacencies);
lsdb.installAdjLsa(failAdjLsa);
// Other router
AdjacencyList otherAdjacencies;
otherAdjacencies.insert(thisRouter);
AdjLsa otherAdjLsa("/ndn/neighborB", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies);
lsdb.installAdjLsa(otherAdjLsa);
// Run the scheduler to build an adjacency LSA
this->advanceClocks(ndn::time::milliseconds(1));
// Make sure an adjacency LSA was built
ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
AdjLsa* lsa = lsdb.findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
uint32_t lastAdjLsaSeqNo = nlsr.getSequencingManager().getAdjLsaSeq();
uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo();
nlsr.getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo);
// Make sure the routing table was calculated
RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
@@ -176,7 +216,11 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
nlsr.getConfParameter().getInterestRetryNumber());
BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
BOOST_CHECK_EQUAL(nlsr.getSequencingManager().getAdjLsaSeq(), lastAdjLsaSeqNo + 1);
lsa = lsdb.findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1);
// Make sure the routing table was recalculated
rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
@@ -192,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
// refresh will not cause RIB entries for other nodes' name prefixes to be refreshed.
BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture)
{
shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace(g_ioService);
shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>(g_ioService);
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
Lsdb& lsdb = nlsr.getLsdb();
@@ -224,7 +268,7 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture)
ndn::Name nameToAdvertise("/ndn/neighborB/name");
nameList.insert(nameToAdvertise);
NameLsa nameLsa("/ndn/neighborB", "name", 25, ndn::time::system_clock::now(), nameList);
NameLsa nameLsa("/ndn/neighborB", 25, ndn::time::system_clock::now(), nameList);
lsdb.installNameLsa(nameLsa);
nlsr.initialize();
@@ -232,6 +276,22 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture)
// Simulate successful HELLO responses from neighbor B
lsdb.scheduleAdjLsaBuild();
// Set up adjacency LSAs
// This router
Adjacent thisRouter(conf.getRouterPrefix(), "uri://faceB", 25, Adjacent::STATUS_ACTIVE, 0, 256);
AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors);
lsdb.installAdjLsa(ownAdjLsa);
// Other ACTIVE router
AdjacencyList otherAdjacencies;
otherAdjacencies.insert(thisRouter);
AdjLsa otherAdjLsa("/ndn/neighborB", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies);
lsdb.installAdjLsa(otherAdjLsa);
// Run the scheduler to build an adjacency LSA
this->advanceClocks(ndn::time::milliseconds(1));
@@ -278,11 +338,8 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture)
BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise);
}
BOOST_FIXTURE_TEST_CASE(GetCertificate, UnitTestTimeFixture)
BOOST_AUTO_TEST_CASE(GetCertificate)
{
shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace(g_ioService);
Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
// Create certificate
ndn::Name identity("/TestNLSR/identity");
identity.appendVersion();
@@ -310,6 +367,84 @@ BOOST_FIXTURE_TEST_CASE(GetCertificate, UnitTestTimeFixture)
BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
}
BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix)
{
// Simulate loading configuration file
ConfParameter& conf = nlsr.getConfParameter();
conf.setNetwork("/ndn");
conf.setSiteName("/site");
conf.setRouterName("/%C1.router/this-router");
nlsr.initialize();
BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(),
ndn::Name("/ndn/site/%C1.router/this-router/lsdb"));
}
BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
{
// Configure NLSR
ConfParameter& conf = nlsr.getConfParameter();
conf.setNetwork("/ndn");
conf.setSiteName("/site");
ndn::Name routerName("/%C1.Router/this-router");
conf.setRouterName(routerName);
conf.setAdjLsaBuildInterval(1);
// Add neighbors
// Router A
ndn::Name neighborAName("/ndn/site/%C1.router/routerA");
Adjacent neighborA(neighborAName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
// Router B
ndn::Name neighborBName("/ndn/site/%C1.router/routerB");
Adjacent neighborB(neighborBName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborB);
nlsr.initialize();
this->advanceClocks(ndn::time::milliseconds(1));
// Receive HELLO response from Router A
receiveHelloData(neighborAName, conf.getRouterPrefix());
this->advanceClocks(ndn::time::seconds(1));
ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING);
// Adjacency LSA should be built even though other router is INACTIVE
AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
BOOST_REQUIRE(lsa != nullptr);
BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1);
// Receive HELLO response from Router B
receiveHelloData(neighborBName, conf.getRouterPrefix());
// Both routers become INACTIVE and HELLO Interests have timed out
for (Adjacent& adjacency : neighbors.getAdjList()) {
adjacency.setStatus(Adjacent::STATUS_INACTIVE);
adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
}
this->advanceClocks(ndn::time::seconds(1));
// Adjacency LSA should have been removed since this router's adjacencies are INACTIVE
// and have timed out
lsa = lsdb.findAdjLsa(lsaKey);
BOOST_CHECK(lsa == nullptr);
// Receive HELLO response from Router A and B
receiveHelloData(neighborAName, conf.getRouterPrefix());
receiveHelloData(neighborBName, conf.getRouterPrefix());
this->advanceClocks(ndn::time::seconds(1));
// Adjacency LSA should be built
lsa = lsdb.findAdjLsa(lsaKey);
BOOST_REQUIRE(lsa != nullptr);
BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
+1 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
+104 -24
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, The University of Memphis,
* Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -20,22 +20,22 @@
**/
#include "test-common.hpp"
#include "dummy-face.hpp"
#include "nlsr.hpp"
#include "communication/sync-logic-handler.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nlsr {
namespace test {
using ndn::DummyFace;
using ndn::shared_ptr;
class SyncLogicFixture : public BaseFixture
{
public:
SyncLogicFixture()
: face(ndn::makeDummyFace())
: face(make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, sync(nlsr.getSyncLogicHandler())
, CONFIG_NETWORK("/ndn")
@@ -49,7 +49,7 @@ public:
}
void
receiveUpdate(std::string prefix, uint64_t seqNo)
receiveUpdate(std::string prefix, uint64_t seqNo, SyncLogicHandler& p_sync)
{
Sync::MissingDataInfo info = {prefix, 0, seqNo};
@@ -57,15 +57,15 @@ public:
updates.push_back(info);
face->processEvents(ndn::time::milliseconds(1));
face->m_sentInterests.clear();
face->sentInterests.clear();
sync.onNsyncUpdate(updates, NULL);
p_sync.onNsyncUpdate(updates, NULL);
face->processEvents(ndn::time::milliseconds(1));
}
public:
shared_ptr<DummyFace> face;
shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
SyncLogicHandler& sync;
@@ -76,34 +76,114 @@ public:
BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
BOOST_AUTO_TEST_CASE(UpdateForOther)
BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
{
std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_SITE + "/%C1.Router/other-router/";
receiveUpdate(updateName, 1);
uint64_t syncSeqNo = 1;
receiveUpdate(updateName, syncSeqNo, sync);
std::vector<ndn::Interest>& interests = face->m_sentInterests;
BOOST_REQUIRE_EQUAL(interests.size(), 3);
std::vector<ndn::Interest>& interests = face->sentInterests;
std::vector<ndn::Interest>::iterator it = interests.begin();
BOOST_REQUIRE_EQUAL(interests.size(), 2);
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
}
BOOST_AUTO_TEST_CASE(UpdateForOtherHR)
{
Nlsr nlsr_hr(g_ioService, g_scheduler, ndn::ref(*face));
SyncLogicHandler& sync_hr(nlsr_hr.getSyncLogicHandler());
nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK);
nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE);
nlsr_hr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
nlsr_hr.getConfParameter().buildRouterPrefix();
nlsr_hr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
nlsr_hr.initialize();
std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_SITE + "/%C1.Router/other-router/";
uint64_t syncSeqNo = 0;
syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
receiveUpdate(updateName, syncSeqNo, sync_hr);
std::vector<ndn::Interest>& interests = face->sentInterests;
std::vector<ndn::Interest>::iterator it = interests.begin();
BOOST_REQUIRE_EQUAL(interests.size(), 2);
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
}
BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry)
{
Nlsr nlsr_hrdry(g_ioService, g_scheduler, ndn::ref(*face));
SyncLogicHandler& sync_hrdry(nlsr_hrdry.getSyncLogicHandler());
nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK);
nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE);
nlsr_hrdry.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
nlsr_hrdry.getConfParameter().buildRouterPrefix();
nlsr_hrdry.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
nlsr_hrdry.initialize();
std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_SITE + "/%C1.Router/other-router/";
uint64_t syncSeqNo = 1;
syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
receiveUpdate(updateName, syncSeqNo, sync_hrdry);
std::vector<ndn::Interest>& interests = face->sentInterests;
std::vector<ndn::Interest>::iterator it = interests.begin();
BOOST_REQUIRE_EQUAL(interests.size(), 3);
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
}
else if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
}
else {
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
++it;
BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
}
}
BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
{
std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_SITE + CONFIG_ROUTER_NAME;
receiveUpdate(updateName, 1);
receiveUpdate(updateName, 1, sync);
std::vector<ndn::Interest>& interests = face->m_sentInterests;
std::vector<ndn::Interest>& interests = face->sentInterests;
BOOST_CHECK_EQUAL(interests.size(), 0);
}
@@ -112,7 +192,7 @@ BOOST_AUTO_TEST_CASE(MalformedUpdate)
std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_ROUTER_NAME;
std::vector<ndn::Interest>& interests = face->m_sentInterests;
std::vector<ndn::Interest>& interests = face->sentInterests;
BOOST_CHECK_EQUAL(interests.size(), 0);
}
@@ -124,17 +204,17 @@ BOOST_AUTO_TEST_CASE(SequenceNumber)
// Install Name LSA
NamePrefixList nameList;
NameLsa lsa(originRouter, NameLsa::TYPE_STRING, 999, ndn::time::system_clock::TimePoint::max(), nameList);
NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
lsdb.installNameLsa(lsa);
// Install Adj LSA
AdjacencyList adjList;
AdjLsa adjLsa(originRouter, AdjLsa::TYPE_STRING, 1000, ndn::time::system_clock::TimePoint::max(),
AdjLsa adjLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
3 , adjList);
lsdb.installAdjLsa(adjLsa);
// Install Cor LSA
CoordinateLsa corLsa(originRouter, CoordinateLsa::TYPE_STRING, 1000, ndn::time::system_clock::TimePoint::max(),
CoordinateLsa corLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
0,0);
lsdb.installCoordinateLsa(corLsa);
@@ -143,23 +223,23 @@ BOOST_AUTO_TEST_CASE(SequenceNumber)
// Lower NameLSA sequence number
uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40;
receiveUpdate(updateName, lowerSeqNo);
receiveUpdate(updateName, lowerSeqNo, sync);
std::vector<ndn::Interest>& interests = face->m_sentInterests;
std::vector<ndn::Interest>& interests = face->sentInterests;
BOOST_REQUIRE_EQUAL(interests.size(), 0);
// Same NameLSA sequence number
uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40;
receiveUpdate(updateName, sameSeqNo);
receiveUpdate(updateName, sameSeqNo, sync);
interests = face->m_sentInterests;
interests = face->sentInterests;
BOOST_REQUIRE_EQUAL(interests.size(), 0);
// Higher NameLSA sequence number
uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40;
receiveUpdate(updateName, higherSeqNo);
receiveUpdate(updateName, higherSeqNo, sync);
interests = face->m_sentInterests;
interests = face->sentInterests;
BOOST_REQUIRE_EQUAL(interests.size(), 1);
std::vector<ndn::Interest>::iterator it = interests.begin();
Loaded 100 of 113 files, more files were not shown because too many files have changed in this diff. Show more