support for NS, TXT, NDNCERT, FH
diff --git a/src/db/db-mgr.cpp b/src/db/db-mgr.cpp
index 5ab9db1..baabad8 100644
--- a/src/db/db-mgr.cpp
+++ b/src/db/db-mgr.cpp
@@ -26,25 +26,22 @@
namespace ndns {
DBMgr::DBMgr()
-: m_dbfile("src/db/ndns-local.db")
-, m_conn(0)
-, m_reCode(-1)
-, m_status(DBClosed)
-, m_resultNum(0)
+ : m_dbfile("src/db/ndns-local.db")
+ , m_conn(0)
+ , m_reCode(-1)
+ , m_status(DBClosed)
+ , m_resultNum(0)
{
std::fstream file;
- file.open(m_dbfile,std::ios::in);
- if (file)
- {
- std::cout<<"database file "<<m_dbfile<<" does exist"<<std::endl;
- } else
- {
- std::cout<<"database file "<<m_dbfile<<" does not exist"<<std::endl;
+ file.open(m_dbfile, std::ios::in);
+ if (file) {
+ std::cout << "database file " << m_dbfile << " does exist" << std::endl;
+ } else {
+ std::cout << "database file " << m_dbfile << " does not exist" << std::endl;
}
}
-
DBMgr::~DBMgr()
{
}
@@ -55,14 +52,12 @@
return;
m_reCode = sqlite3_open(this->m_dbfile.c_str(), &(this->m_conn));
- if (m_reCode != SQLITE_OK)
- {
- m_err = "Cannot connect to the db: "+this->m_dbfile;
+ if (m_reCode != SQLITE_OK) {
+ m_err = "Cannot connect to the db: " + this->m_dbfile;
m_status = DBError;
//exit(1);
- }else
- {
- std::cout<<"connect to the db: "<<m_dbfile<<std::endl;
+ } else {
+ std::cout << "connect to the db: " << m_dbfile << std::endl;
}
m_status = DBConnected;
}
@@ -73,15 +68,15 @@
return;
m_reCode = sqlite3_close(this->m_conn);
- if (m_reCode != SQLITE_OK)
- {
- m_err = "Cannot close the db: "+this->m_dbfile;
- m_status = DBError;
+ if (m_reCode != SQLITE_OK) {
+ m_err = "Cannot close the db: " + this->m_dbfile;
+ m_status = DBError;
}
m_status = DBClosed;
}
-void DBMgr::execute(std::string sql, int (*callback)(void*,int,char**,char**), void * paras)
+void DBMgr::execute(std::string sql,
+ int (*callback)(void*, int, char**, char**), void * paras)
{
if (m_status == DBClosed)
this->open();
@@ -89,15 +84,14 @@
clearResultNum();
char *err_msg;
m_reCode = sqlite3_exec(m_conn, sql.c_str(), callback, paras, &err_msg);
- if (m_reCode != SQLITE_OK)
- {
+ if (m_reCode != SQLITE_OK) {
m_status = DBError;
this->m_err.append(err_msg);
- std::cout<<this->m_err<<std::endl;
+ std::cout << this->m_err << std::endl;
}
this->close();
}
-}//namespace ndns
-}//namespace ndn
+} //namespace ndns
+} //namespace ndn
diff --git a/src/db/db-mgr.hpp b/src/db/db-mgr.hpp
index c6445af..ab016e1 100644
--- a/src/db/db-mgr.hpp
+++ b/src/db/db-mgr.hpp
@@ -23,19 +23,15 @@
#include <sqlite3.h>
#include <iostream>
-
namespace ndn {
namespace ndns {
-
class DBMgr
{
public:
enum m_status
{
- DBConnected,
- DBClosed,
- DBError
+ DBConnected, DBClosed, DBError
};
public:
@@ -44,57 +40,68 @@
void open();
void close();
- void execute(std::string sql,
- int (*callback)(void*,int,char**,char**), void * paras);
+ void execute(std::string sql, int (*callback)(void*, int, char**, char**),
+ void * paras);
- inline void addResultNum(){
+ inline void addResultNum()
+ {
m_resultNum += 1;
}
- inline void clearResultNum() {
+ inline void clearResultNum()
+ {
m_resultNum = 0;
}
- const std::string& getDbfile() const {
+ const std::string& getDbfile() const
+ {
return m_dbfile;
}
- void setDbfile(const std::string& dbfile) {
+ void setDbfile(const std::string& dbfile)
+ {
this->m_dbfile = dbfile;
}
- const std::string& getErr() const {
+ const std::string& getErr() const
+ {
return m_err;
}
- void setErr(const std::string& err) {
+ void setErr(const std::string& err)
+ {
this->m_err = err;
}
- int getReCode() const {
+ int getReCode() const
+ {
return m_reCode;
}
- void setReCode(int reCode) {
+ void setReCode(int reCode)
+ {
this->m_reCode = reCode;
}
- m_status getStatus() const {
+ m_status getStatus() const
+ {
return m_status;
}
- void setStatus(m_status status) {
+ void setStatus(m_status status)
+ {
this->m_status = status;
}
- int getResultNum() const {
+ int getResultNum() const
+ {
return m_resultNum;
}
- void setResultNum(int resultNum) {
+ void setResultNum(int resultNum)
+ {
m_resultNum = resultNum;
}
-
private:
std::string m_dbfile;
sqlite3 *m_conn;
@@ -102,8 +109,9 @@
int m_reCode;
m_status m_status;
int m_resultNum;
-}; //class DBMgr
+};
+//class DBMgr
}//namespace ndns
-}//namespace ndn
+} //namespace ndn
#endif
diff --git a/src/db/ndns-db-data-demo.sql b/src/db/ndns-db-data-demo.sql
index 8564207..6567c5b 100644
--- a/src/db/ndns-db-data-demo.sql
+++ b/src/db/ndns-db-data-demo.sql
@@ -1,4 +1,7 @@
-
+/*
+sqlite3 src/db/ndns-local.db
+.read ndns-db-data-demo.sql
+*/
delete from rrs;
delete from rrsets;
delete from zones;
@@ -8,33 +11,102 @@
(2, "/net"),
(3, "/net/ndnsim"),
(4, "/dns/google/com"),
- (5, "/net/ndnsim/git/doc")
+ (5, "/net/ndnsim/git/doc"),
+
+ (6, "/com"),
+ (7, "/com/skype")
;
insert into rrsets (id, zone_id, label, class, type, ndndata) values
+ /* NS of sub-domain */
+ (4, 1, "/net", NULL, "NS", NULL),
+ (3, 2, "/ndnsim", NULL, "NS", NULL),
+ (7, 3, "/git/doc", NULL, "NS", NULL),
+
+ /* FH of NS (name servers) */
+ (21, 1, "/net/ns1", NULL, "FH", NULL),
+ (18, 2, "/net/ndnsim/ns1", NULL, "FH", NULL),
+ (19, 3, "/net/ndnsim/git/doc/ns1", NULL, "FH", NULL),
+
+ /* TXT of service/app*/
(1, 3, "/www", NULL, "TXT", NULL),
(2, 3, "/doc", NULL, "TXT", NULL),
- (3, 2, "/ndnsim", NULL, "NS", NULL),
- (4, 1, "/net", NULL, "NS", NULL),
- (5, 4, "/net", NULL, "NS", NULL),
(6, 3, "/git/www", NULL, "TXT", NULL),
- (7, 3, "/git/doc", NULL, "NS", NULL),
- (8, 5, "/www", NULL, "TXT", NULL),
(9, 3, "/repo/www", NULL, "TXT", NULL),
- (10, 3, "/norrdata", NULL, "TXT", NULL)
+ (8, 5, "/www", NULL, "TXT", NULL),
+ (10, 3, "/norrdata", NULL, "TXT", NULL),
+
+ /* FH of physical hosts, which is not named by hierarchical */
+ (25, 3, "/net/ndnsim/www/h1", NULL, "FH", NULL),
+ (26, 3, "/net/ndnsim/h1", NULL, "FH", NULL),
+ (27, 3, "/net/ndnsim/h2", NULL, "FH", NULL),
+ (28, 5, "/net/ndnsim/git/doc/h1", NULL, "FH", NULL),
+
+ /* NDNCERT of domain */
+ (11, 3, "/www/dsk-1", NULL, "NDNCERT", NULL),
+ (12, 3, "/www/ksk-1", NULL, "NDNCERT", NULL),
+ (13, 3, "/dsk-1", NULL, "NDNCERT", NULL),
+ (14, 2, "/ndnsim/ksk-1", NULL, "NDNCERT", NULL),
+ (15, 2, "/dsk-1", NULL, "NDNCERT", NULL),
+ (16, 1, "/net/ksk-1", NULL, "NDNCERT", NULL),
+ (17, 1, "/root", NULL, "NDNCERT", NULL),
+
+ /* Mobility Support for Skype (NDN rtc in the future) */
+ (100, 1, "/com", NULL, "NS", NULL),
+ (101, 6, "/skype", NULL, "NS", NULL),
+ (102, 1, "/com/ns1", NULL, "FH", NULL),
+ (103, 6, "/com/skype/ns1", NULL, "FH", NULL),
+
+ (105, 7, "/shock", NULL, "FH", NULL),
+ (106, 7, "/alex", NULL, "FH", NULL),
+ (107, 7, "/lixia", NULL, "FH", NULL),
+ (108, 7, "/yiding", NULL, "FH", NULL)
;
insert into rrs (id, rrset_id, ttl, rrdata) values
- (1, 1, 3600, "/ucla"),
- (2, 1, 8000, "/att"),
- (3, 2, 3600, "/ucla"),
- (4, 3, 4000, "/net/ndnsim2"),
- (5, 4, 5000, "/net"),
- (6, 5, 6000, "/net"),
- (7, 3, 4000, "/net/ndnsim"),
- (8, 6, 3000, "/net/ndnsim/git/www"),
- (9, 7, 3000, "/net/ndnsim/git/doc"),
- (10,8, 3000, "/net/ndnsim/git/doc/www"),
- (11,9, 3000, "/net/ndnsim/repo/www")
+ /* NS */
+ (31, 4, 3600, "/net/ns1"),
+ (32, 3, 3600, "/net/ndnsim/ns1"),
+ (33, 7, 3600, "/net/ndnsim/git/doc/ns1"),
+
+ /* FH of NS (name server) */
+ (20, 21, 3600, "/sprint"),
+ (21, 18, 3600, "/ucla"),
+ (22, 19, 3600, "/ucla"),
+
+ /* TXT of service/app */
+ (1, 1, 3600, "/net/ndnsim/www/h1"),
+ (2, 1, 8000, "/net/ndnsim/h1"),
+ (3, 2, 3600, "/net/ndnsim/www/h1"),
+ (8, 6, 3000, "/net/ndnsim/h1"),
+ (11,9, 3000, "/net/ndnsim/h2"),
+ (10,8, 3000, "/net/ndnsim/git/doc/h1"),
+
+ /* rrdata of FH of physical hosts, rrdata is FH */
+ (25, 25, 3000, "/ucla"),
+ (26, 26, 3000, "/ucla"),
+ (27, 27, 3000, "/ucla"),
+ (28, 28, 3000, "/ucla"),
+
+ /* NDNCERT*/
+ (12,11,3000, "/net/ndnsim/DNS/www/dsk-1:010010101101010101"),
+ (13,12,3000, "/net/ndnsim/DNS/www/ksk-1:0101111010001111110"),
+ (14,13,3000, "/net/ndnsim/DNS/dsk-1:1010110101"),
+ (15,14,3000, "/net/DNS/ndnsim/ksk-1:0101010101010111100011010"),
+ (16,15,3000, "/net/DNS/dsk-1:01111010101036654646"),
+ (17,16,3000, "/DNS/net/ksk-1:43a13f1a3d13a"),
+ (18,17,3000, "/KEY/ROOT:44631346541aaaf"),
+
+ /* Mobility Support for Skype */
+ (100, 100, 3000, "/com/ns1"),
+ (101, 101, 3000, "/com/skype/ns1"),
+ (102, 102, 3000, "/bt"),
+ (103, 103, 3000, "/verizon"),
+
+ (104, 105, 3000, "/ucla"),
+ (105, 105, 3000, "/att"),
+ (106, 106, 3000, "/ucla"),
+ (107, 107, 3000, "/ucla"),
+ (108, 108, 3000, "/ucla")
;
diff --git a/src/db/ndns-local.db b/src/db/ndns-local.db
index a9177ca..b844390 100644
--- a/src/db/ndns-local.db
+++ b/src/db/ndns-local.db
Binary files differ
diff --git a/src/db/rr-mgr.cpp b/src/db/rr-mgr.cpp
index 51e0e3b..0d4588d 100644
--- a/src/db/rr-mgr.cpp
+++ b/src/db/rr-mgr.cpp
@@ -8,7 +8,7 @@
#include "rr-mgr.hpp"
namespace ndn {
-namespace ndns{
+namespace ndns {
RRMgr::RRMgr(Zone& zone, Query& query, Response& response)
: m_count(0U)
, m_zone(zone)
@@ -18,18 +18,15 @@
}
-
-RRMgr::~RRMgr() {
+RRMgr::~RRMgr()
+{
// TODO Auto-generated destructor stub
}
-
-
-int
-RRMgr::count()
+int RRMgr::count()
{
std::string sql;
- sql = "SELECT count(*) FROM rrs INNER JOIN rrsets ON rrs.rrset_id=rrsets.id";
+ sql = "SELECT count(*) FROM rrs INNER JOIN rrsets ON rrs.rrset_id=rrsets.id";
sql += " WHERE rrsets.zone_id=";
sql += std::to_string(m_zone.getId());
sql += " AND ";
@@ -37,24 +34,23 @@
sql += RR::toString(m_query.getRrType());
sql += "\' AND ";
sql += "rrsets.label LIKE\'";
- sql += m_query.getRrLabel().toUri()+"/%\'";
+ sql += m_query.getRrLabel().toUri() + "/%\'";
- std::cout<<"sql="<<sql<<std::endl;
+ std::cout << "sql=" << sql << std::endl;
this->execute(sql, static_callback_countRr, this);
- if (this->getStatus() == DBMgr::DBError)
- {
+ if (this->getStatus() == DBMgr::DBError) {
return -1;
}
return this->m_count;
}
-int
-RRMgr::callback_countRr(int argc, char **argv, char **azColName)
+int RRMgr::callback_countRr(int argc, char **argv, char **azColName)
{
this->addResultNum();
- std::cout<<this->getResultNum()<<"th result: "<<"count="<<argv[0]<<std::endl;
+ std::cout << this->getResultNum() << "th result: " << "count=" << argv[0]
+ << std::endl;
m_count = std::atoi(argv[0]);
return 0;
}
@@ -63,7 +59,8 @@
{
std::string sql;
- sql = "SELECT rrs.ttl, rrs.rrdata, rrs.id FROM rrs INNER JOIN rrsets ON rrs.rrset_id=rrsets.id";
+ sql =
+ "SELECT rrs.ttl, rrs.rrdata, rrs.id FROM rrs INNER JOIN rrsets ON rrs.rrset_id=rrsets.id";
sql += " WHERE rrsets.zone_id=";
sql += std::to_string(m_zone.getId());
sql += " AND ";
@@ -71,14 +68,13 @@
sql += RR::toString(m_query.getRrType());
sql += "\' AND ";
sql += "rrsets.label=\'";
- sql += m_query.getRrLabel().toUri()+"\'";
+ sql += m_query.getRrLabel().toUri() + "\'";
sql += " ORDER BY rrs.id";
- std::cout<<"sql="<<sql<<std::endl;
+ std::cout << "sql=" << sql << std::endl;
this->execute(sql, static_callback_getRr, this);
- if (this->getStatus() == DBMgr::DBError)
- {
+ if (this->getStatus() == DBMgr::DBError) {
return -1;
}
@@ -89,16 +85,16 @@
int RRMgr::callback_getRr(int argc, char **argv, char **azColName)
{
this->addResultNum();
- if (argc < 1)
- {
- this->setErr("No RRType="+RR::toString(m_query.getRrType())+
- " and label="+m_query.getRrLabel().toUri()+
- " and zone="+m_zone.getAuthorizedName().toUri());
+ if (argc < 1) {
+ this->setErr(
+ "No RRType=" + RR::toString(m_query.getRrType()) + " and label="
+ + m_query.getRrLabel().toUri() + " and zone="
+ + m_zone.getAuthorizedName().toUri());
return 0;
}
- std::cout<<this->getResultNum()<<"th result: "<<"id="<<argv[2]
- <<" ttl="<<argv[0]<<" rrdata="<<argv[1]<<std::endl;
+ std::cout << this->getResultNum() << "th result: " << "id=" << argv[2]
+ << " ttl=" << argv[0] << " rrdata=" << argv[1] << std::endl;
m_response.setFreshness(time::milliseconds(std::atoi(argv[0])));
@@ -108,5 +104,5 @@
return 0;
}
-}//namespace ndnsn
+} //namespace ndnsn
} /* namespace ndn */
diff --git a/src/db/rr-mgr.hpp b/src/db/rr-mgr.hpp
index e940d10..b1f33d0 100644
--- a/src/db/rr-mgr.hpp
+++ b/src/db/rr-mgr.hpp
@@ -25,12 +25,12 @@
#include "response.hpp"
#include "zone.hpp"
-
namespace ndn {
-namespace ndns{
-class RRMgr : public DBMgr {
+namespace ndns {
+class RRMgr: public DBMgr
+{
public:
- RRMgr( Zone& zone, Query& query, Response& response);
+ RRMgr(Zone& zone, Query& query, Response& response);
virtual ~RRMgr();
public:
@@ -38,44 +38,50 @@
int callback_getRr(int argc, char **argv, char **azColName);
- static int
- static_callback_getRr(void *param, int argc, char **argv, char **azColName)
+ static int static_callback_getRr(void *param, int argc, char **argv,
+ char **azColName)
{
RRMgr *mgr = reinterpret_cast<RRMgr*>(param);
return mgr->callback_getRr(argc, argv, azColName);
- }
+ }
int count();
int callback_countRr(int argc, char **argv, char **azColName);
- static int
- static_callback_countRr(void *param, int argc, char **argv, char **azColName)
+ static int static_callback_countRr(void *param, int argc, char **argv,
+ char **azColName)
{
RRMgr *mgr = reinterpret_cast<RRMgr*>(param);
return mgr->callback_countRr(argc, argv, azColName);
- }
+ }
- const Query& getQuery() const {
+ const Query& getQuery() const
+ {
return m_query;
}
- void setQuery(const Query& query) {
+ void setQuery(const Query& query)
+ {
m_query = query;
}
- const Response& getResponse() const {
+ const Response& getResponse() const
+ {
return m_response;
}
- void setResponse(const Response& response) {
+ void setResponse(const Response& response)
+ {
m_response = response;
}
- const Zone& getZone() const {
+ const Zone& getZone() const
+ {
return m_zone;
}
- void setZone(const Zone& zone) {
+ void setZone(const Zone& zone)
+ {
m_zone = zone;
}
@@ -86,8 +92,6 @@
Response& m_response;
};
-
-
} //namespace ndns
} /* namespace ndn */
diff --git a/src/db/zone-mgr.cpp b/src/db/zone-mgr.cpp
index cc0b613..4efc285 100644
--- a/src/db/zone-mgr.cpp
+++ b/src/db/zone-mgr.cpp
@@ -19,59 +19,50 @@
#include "zone-mgr.hpp"
-
namespace ndn {
namespace ndns {
-ZoneMgr::ZoneMgr( Zone& zone)
-: m_zone(zone)
+ZoneMgr::ZoneMgr(Zone& zone)
+ : m_zone(zone)
{
this->lookupId();
}
-void
-ZoneMgr::lookupId(const Name& name)
+void ZoneMgr::lookupId(const Name& name)
{
this->open();
- std::string sql = "SELECT id FROM zones WHERE name=\'"+name.toUri()+"\'";
+ std::string sql = "SELECT id FROM zones WHERE name=\'" + name.toUri() + "\'";
//sql = "SELECT * FROM ZONES";
- std::cout<<"sql="<<sql<<std::endl;
+ std::cout << "sql=" << sql << std::endl;
//std::cout<<"*this="<<this<<" m_zone.id="<<m_zone.getId()<<" zoneId="<<&m_zone<<std::endl;
this->execute(sql, static_callback_setId, this);
//std::cout<<"*this="<<this<<" m_zone.id="<<m_zone.getId()<<" zoneId="<<&m_zone<<std::endl;
this->close();
}
-int
-ZoneMgr::callback_setId(int argc, char **argv, char **azColName)
+int ZoneMgr::callback_setId(int argc, char **argv, char **azColName)
{
//Zone zone = this->getZone();
this->addResultNum();
Zone zone = this->m_zone;
- if (argc < 1)
- {
- this->setErr("No Zone with Name "+zone.getAuthorizedName().toUri());
+ if (argc < 1) {
+ this->setErr("No Zone with Name " + zone.getAuthorizedName().toUri());
return -1;
}
//std::cout<<"id="<<(uint32_t)std::atoi(argv[0])<<" "<<std::endl;
int t1 = std::atoi(argv[0]);
-
m_zone.setId(t1);
return 0;
}
-void
-ZoneMgr::lookupId()
+void ZoneMgr::lookupId()
{
lookupId(this->m_zone.getAuthorizedName());
}
-
-}//namepsace ndns
-}//namespace ndn
-
-
+} //namepsace ndns
+} //namespace ndn
diff --git a/src/db/zone-mgr.hpp b/src/db/zone-mgr.hpp
index 8ced971..faf8f27 100644
--- a/src/db/zone-mgr.hpp
+++ b/src/db/zone-mgr.hpp
@@ -29,11 +29,11 @@
namespace ndn {
namespace ndns {
-class ZoneMgr : public DBMgr
+class ZoneMgr: public DBMgr
{
public:
- ZoneMgr( Zone& zone);
+ ZoneMgr(Zone& zone);
public:
void
@@ -42,31 +42,32 @@
void
lookupId();
- const Zone& getZone() const {
+ const Zone& getZone() const
+ {
return m_zone;
}
- void setZone(const Zone& zone) {
+ void setZone(const Zone& zone)
+ {
this->m_zone = zone;
}
int
callback_setId(int argc, char **argv, char **azColName);
+ static int static_callback_setId(void *param, int argc, char **argv,
+ char **azColName)
+ {
- static int
- static_callback_setId(void *param, int argc, char **argv, char **azColName){
-
- ZoneMgr *mgr = reinterpret_cast<ZoneMgr*>(param);
- return mgr->callback_setId(argc, argv, azColName);
- }
+ ZoneMgr *mgr = reinterpret_cast<ZoneMgr*>(param);
+ return mgr->callback_setId(argc, argv, azColName);
+ }
private:
Zone& m_zone;
-};//class ZoneMgr
-
-
+};
+//class ZoneMgr
}//namespace ndns
-}//namespace ndn
+} //namespace ndn
#endif