Merge pull request 'pull-base' (#1) from pull-base into main

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2021-10-05 22:09:24 +08:00
9 changed files with 405 additions and 75 deletions
+214
View File
@@ -0,0 +1,214 @@
# IP tunnel
This project implements NDN-based IP tunnel and MIN-based IP tunnel to compare the performance of the two.
## 1. Experiment intro
![多标识路由器设计](https://gitee.com/quejianming/pic-bed/raw/master/uPic/2021/10/05/%E5%A4%9A%E6%A0%87%E8%AF%86%E8%B7%AF%E7%94%B1%E5%99%A8%E8%AE%BE%E8%AE%A1-1633441220.svg)
We implement an IP tunnel based on MIN and NDN, respectively, and compare the performance of the two network architectures in this scenario. The experimental topology is shown in the above figure, with R1, R2, and R3 running on three Linux servers whose configuration information is shown in the following table. Each server runs a MIN/NDN as a network router, and they are directly connected via an ethernet link. We implement a TUN tunnel on the edge router, which collects IP packets sent to the TUN interface and encapsulates them into MIN/NDN packets. Then, IP packets are transmitted to the edge router on the other side through MIN/NDN communication. Considering that MIN/NDN packets have some header overhead, to avoid fragmentation, we set the MTU of the TUN interface to 1500 and the MTU of the interface connected between routers to 2000. We will use *iperf3* to measure the network's performance using MIN/NDN as an IP tunnel.
| CPU | RAM | Operating System | Software Version |
| --------------------------------------------------- | ----- | ---------------- | --------------------- |
| Intel\(R\) Xeon\(R\) Gold 5118 CPU @ 2\.30GHz \* 96 | 128GB | Ubuntu 20.04.3 | MIR v0.1.0;NFD v0.7.1 |
## 2. Install
### 2.1 Running MIN IP Tunnel
Since MIN is not open source yet, only the experimental code is given here, and no operation guidance is provided.
### 2.2 Runnin NDN IP Tunnel
We should config three Linux servers, each server running a Ubuntu 20.04 operating system.
#### 2.2.1 Install NFD environment
- Linux Server 1:
```bash
git clone https://gitea.qjm253.cn/SunnyQjm/NDNInstaller.git
cd NDNInstaller
./install_ndn-cxx.sh
./install_nfd.sh
./install_ndn-tools.sh
```
- Linux Server 2:
```bash
git clone https://gitea.qjm253.cn/SunnyQjm/NDNInstaller.git
cd NDNInstaller
./install_ndn-cxx.sh
./install_nfd.sh
./install_ndn-tools.sh
```
- Linux Server 3:
```bash
git clone https://gitea.qjm253.cn/SunnyQjm/NDNInstaller.git
cd NDNInstaller
./install_ndn-cxx.sh
./install_nfd.sh
./install_ndn-tools.sh
```
#### 2.2.2 Config and running NFD
- First running NFD in all Linux Server
```bash
# Linux Server 1, execute follow command
nfd-start
# Linux Server 2, execute follow command
nfd-start
# Linux Server 3, execute follow command
nfd-start
```
- Then create an ethernet face
- Linux Server 1:
```bash
nfdc face create remote ether://[76:8f:3c:bb:65:31] local dev://eno1
# after execute above command, you will get a face id
nfdc route add prefix /pkusz/C nexthop <face-id>
```
- Linux Server 2:
```bash
nfdc face create remote ether://[76:8f:3c:bb:64:31] local dev://eno1
# after execute above command, you will get a face id
nfdc route add prefix /pkusz/B nexthop <face-id>
nfdc face create remote ether://[76:8f:3c:bb:66:31] local dev://eno2
# after execute above command, you will get a face id
nfdc route add prefix /pkusz/C nexthop <face-id>
```
- Linux Server 3:
```bash
nfdc face create remote ether://[76:8f:3c:bb:65:32] local dev://eno1
# after execute above command, you will get a face id
nfdc route add prefix /pkusz/B nexthop <face-id>
```
#### 2.2.3 Config and running NDN-based IP Tunnel
- modify config file
- Linux Server 1:
Edit iptunconf.inireplace the config file value as follow:
```ini
[Tun]
InterfaceName = tun0
IPv4Addr = 192.168.88.1
Mtu = 1500
Mask = 255.255.255.0
Route = 192.168.90.0/24
[Mir]
UnixSocketPath = /tmp/mir.sock
ListenIdentifier = /pkusz/B
TargetIdentifier = /pkusz/C
[Log]
LogLevel = WARN
```
- Linux Server 3:
Edit iptunconf.inireplace the config file value as follow:
```bash
[Tun]
InterfaceName = tun0
IPv4Addr = 192.168.88.2
Mtu = 1500
Mask = 255.255.255.0
Route = 192.168.89.0/24
[Mir]
UnixSocketPath = /tmp/mir.sock
ListenIdentifier = /pkusz/C
TargetIdentifier = /pkusz/B
[Log]
LogLevel = WARN
```
- running IP Tunnel
- Linux Server 1:
```bash
# cd to ip-tunnel/ndniptunnel, then execute follow command
go run .
```
- Linux Server 3:
```bash
# cd to ip-tunnel/ndniptunnel, then execute follow command
go run .
```
- Test whether the tunnel is established successfully
- Linux Server 1:
```bash
ping 192.168.90.1
```
#### 2.2.4 Running experiment test
- Linux Server 3:
```bash
iperf3 -s -B 192.168.90.1
```
- Linux Server 1:
- Test TCP:
```bash
# 1 Client
iperf3 -c 192.168.90.1 -B 192.168.89.1 -t 60
# 2 Client
iperf3 -c 192.168.90.1 -B 192.168.89.1 -t 60 -P 2
# 5 Client
iperf3 -c 192.168.90.1 -B 192.168.89.1 -t 60 -P 5
# 10 Client
iperf3 -c 192.168.90.1 -B 192.168.89.1 -t 60 -P 10
```
- Test UDP:
```bash
# 100Mbps
iperf3 -c 192.168.90.1 -B 192.168.89.1 -u -l 1400 -t 60 -b 100m -R
# 200Mbps
iperf3 -c 192.168.90.1 -B 192.168.89.1 -u -l 1400 -t 60 -b 200m -R
# 300Mbps
iperf3 -c 192.168.90.1 -B 192.168.89.1 -u -l 1400 -t 60 -b 300m -R
# 400Mbps
iperf3 -c 192.168.90.1 -B 192.168.89.1 -u -l 1400 -t 60 -b 400m -R
# 500Mbps
iperf3 -c 192.168.90.1 -B 192.168.89.1 -u -l 1400 -t 60 -b 500m -R
```
## 3. Result
The example of test data you can get from [min-graph/result_1500]([min-graph/result_1500 at main · SunnyQjm/min-graph (github.com)](https://github.com/SunnyQjm/min-graph/tree/main/result_1500))
The analysis code you can get from [min-graph]([SunnyQjm/min-graph (github.com)](https://github.com/SunnyQjm/min-graph))
+1 -1
View File
@@ -153,7 +153,7 @@ func (i *IPTun) StartTunnel(adapter TunnelAdapter) {
}
}(wg.Done)
// 在单独的协程里面接收CPacket,并从中提取出 IP 包写入到TUN当中
// 在单独的协程里面接收UPPkt,并从中提取出 IP 包写入到TUN当中
go func(done func()) {
defer wg.Done()
for {
+17 -17
View File
@@ -62,8 +62,8 @@ func (M *MINTunnelAdapter) Init(config *iptun.IPTunnelConfig) error {
// OnReceiveIPPktFromTun 处理从TUN网卡接收到的IP包
//
// @Description:
// 1. 生成一个 CPacket,将IP包放进去
// 2. 然后将 CPacket 发出即可
// 1. 生成一个 UPPkt,将IP包放进去
// 2. 然后将 UPPkt 发出即可
// @receiver M
// @param packet
//
@@ -77,22 +77,22 @@ func (M *MINTunnelAdapter) OnReceiveIPPktFromTun(ipPacket *iptun.IPPacket) error
return err
}
// 在这边构造CPacket发出
cPacket := new(packet.CPacket)
cPacket.SetTtl(5)
cPacket.SetSrcIdentifier(srcIdentifier)
cPacket.SetDstIdentifier(dstIdentifier)
cPacket.Payload.SetValue(ipPacket.RawPackets)
// 在这边构造UPPkt发出
uPPkt := new(packet.UPPkt)
uPPkt.SetTtl(5)
uPPkt.SetSrcIdentifier(srcIdentifier)
uPPkt.SetDstIdentifier(dstIdentifier)
uPPkt.Payload.SetValue(ipPacket.RawPackets)
common.LogDebug(fmt.Sprintf("Packet Received: %v -> %v \t %x\n", ipPacket.Src.String(), ipPacket.Dst.String(),
ipPacket.RawPackets))
if err := M.logicFace.SendCPacket(cPacket); err != nil {
if err := M.logicFace.SendUPPkt(uPPkt); err != nil {
return err
}
return nil
}
// ReadIPPkt 从MIN网络中接收携带 IP 包的 CPacket,并
// ReadIPPkt 从MIN网络中接收携带 IP 包的 UPPkt,并
//
// @Description:
// @receiver M
@@ -100,17 +100,17 @@ func (M *MINTunnelAdapter) OnReceiveIPPktFromTun(ipPacket *iptun.IPPacket) error
// @return error
//
func (M *MINTunnelAdapter) ReadIPPkt() (*iptun.IPPacket, error) {
cPacket, err := M.logicFace.ReceiveCPacket(4000)
uPPkt, err := M.logicFace.ReceiveUPPkt(4000)
if err != nil {
return nil, err
} else {
common.LogDebug(fmt.Sprintf("Write %d bytes, %s -> %s, %x", len(cPacket.Payload.GetValue()),
waterutil.IPv4Source(cPacket.Payload.GetValue()),
waterutil.IPv4Destination(cPacket.Payload.GetValue()), cPacket.Payload.GetValue()))
common.LogDebug(fmt.Sprintf("Write %d bytes, %s -> %s, %x", len(uPPkt.Payload.GetValue()),
waterutil.IPv4Source(uPPkt.Payload.GetValue()),
waterutil.IPv4Destination(uPPkt.Payload.GetValue()), uPPkt.Payload.GetValue()))
}
return &iptun.IPPacket{
Src: waterutil.IPv4Source(cPacket.Payload.GetValue()),
Dst: waterutil.IPv4Destination(cPacket.Payload.GetValue()),
RawPackets: cPacket.Payload.GetValue(),
Src: waterutil.IPv4Source(uPPkt.Payload.GetValue()),
Dst: waterutil.IPv4Destination(uPPkt.Payload.GetValue()),
RawPackets: uPPkt.Payload.GetValue(),
}, nil
}
+7 -2
View File
@@ -13,9 +13,14 @@
static MNetIO mNetIO ;
int sendInterest(char *buf, int size, char *name){
return mNetIO.sendInterest(buf, size, name) ;
int sendInterest(char *name){
return mNetIO.sendInterest(name) ;
}
int sendData(char *buf, int size, char *name) {
return mNetIO.sendData(buf, size, name);
}
int start(char *buf, int size){
char prefix[2000] ;
memcpy(prefix, buf, size) ;
+2 -1
View File
@@ -12,7 +12,8 @@
extern "C" {
#endif
int sendInterest(char *buf, int size, char *name) ;
int sendInterest(char *name) ;
int sendData(char *buf, int size, char *name) ;
int start(char *buf, int size) ;
+3 -1
View File
@@ -16,7 +16,9 @@ extern "C" {
//void OnData(char*);
void GoOnData(char *buf, int size) ;
void GoOnInterest(char *buf, int size) ;
void GoOnInterest(char *name) ;
void GoOnTimeout();
void GoOnNack();
#ifdef __cplusplus
}
+66 -28
View File
@@ -19,36 +19,67 @@ MNetIO::MNetIO (){
MNetIO::~MNetIO (){
}
int MNetIO::sendInterest(char *buf, int size, char *name) {
int MNetIO::sendInterest(char *name) {
static uint64_t interestSeq = 0;
Name interestName(name) ;
interestName.appendSequenceNumber(interestSeq++);
string myName = string(name) + "/" + to_string(interestSeq++);
Name interestName(myName) ;
// interestName.appendSequenceNumber(interestSeq++);
Interest interest(interestName);
interest.setInterestLifetime(4_s);
interest.setInterestLifetime(1_s);
// interest.setMustBeFresh(true);
interest.setApplicationParameters((const uint8_t*)buf, size);
// interest.setApplicationParameters((const uint8_t*)buf, size);
// mKeyChain.sign(interest) ;
mFace.expressInterest(interest,
bind(&MNetIO::onData, this, _1, _2),
bind(&MNetIO::onNack, this, _1, _2),
bind(&MNetIO::onTimeout, this, _1));
mFace.removeAllPendingInterests();
// std::cout << "send interest : " << interestSeq << std::endl;
// mFace.removeAllPendingInterests();
// std::cout << "send interest : " << interestName.toUri() << std::endl;
return 0 ;
}
int MNetIO::sendData(char *buf, int size, char *name) {
Name dataName(name);
// std::cout << "send data : " << dataName.toUri() << std::endl;
// Create Data packet
auto data = make_shared<Data>(dataName);
data->setFreshnessPeriod(0_s);
if (size > 0) {
data->setContent(reinterpret_cast<const uint8_t *>(buf), size);
}
string dsha = "id:/localhost/identity/digest-sha256";
ndn::security::SigningInfo si(dsha);
// Sign Data packet with default identity
mKeyChain.sign(*data, si);
mFace.put(*data);
return 0;
}
void MNetIO::onData(const Interest& interest, const Data& data){
// std::cout << "onData : " << std::endl;
char buf[9000];
if(data.getContent().value_size() <= 0){
GoOnData(buf, 0);
} else {
int payloadSz = data.getContent().value_size();
memcpy(buf, data.getContent().value(), payloadSz);
string tmp(buf, payloadSz) ;
GoOnData(buf, payloadSz);
}
}
void MNetIO::onNack(const Interest& interest, const lp::Nack& nack){
// std::cout << "onNack : " << nack.getReason() << std::endl;
GoOnNack();
}
void MNetIO::onTimeout(const Interest& interest){
// std::cout << "onTimeout : " << interest << std::endl;
GoOnTimeout();
}
int MNetIO::start(char *prefix) {
@@ -61,30 +92,37 @@ int MNetIO::start(char *prefix) {
}
void MNetIO::onInterest(const InterestFilter& filter, const Interest& interest){
char buf[9000];
if(!interest.hasApplicationParameters() ||
interest.getApplicationParameters().value_size() <= 0) return ;
int payloadSz = interest.getApplicationParameters().value_size();
memcpy(buf, interest.getApplicationParameters().value(), payloadSz);
string tmp(buf, payloadSz) ;
// char buf[9000];
// if(!interest.hasApplicationParameters() ||
// interest.getApplicationParameters().value_size() <= 0) return ;
// int payloadSz = interest.getApplicationParameters().value_size();
// memcpy(buf, interest.getApplicationParameters().value(), payloadSz);
// string tmp(buf, payloadSz) ;
//onInterest(buf, payloadSz) ;
GoOnInterest(buf, payloadSz);
string nameStr = interest.getName().toUri();
// memcpy(buf, nameStr.c_str(), nameStr.size());
char buf[9000];
memcpy(buf, nameStr.c_str(), nameStr.size());
buf[nameStr.size()] = '\0';
// std::cout << "before oninterest" << std::endl;
GoOnInterest(buf);
// std::cout << "after oninterest" << std::endl;
// Create Data packet
auto data = make_shared<Data>(interest.getName());
data->setFreshnessPeriod(0_s);
// // Create Data packet
// auto data = make_shared<Data>(interest.getName());
// data->setFreshnessPeriod(0_s);
string dsha = "id:/localhost/identity/digest-sha256";
ndn::security::SigningInfo si(dsha);
// Sign Data packet with default identity
mKeyChain.sign(*data, si);
// m_keyChain.sign(*data, signingByIdentity(<identityName>));
// m_keyChain.sign(*data, signingByKey(<keyName>));
// m_keyChain.sign(*data, signingByCertificate(<certName>));
// m_keyChain.sign(*data, signingWithSha256());
// Return Data packet to the requester
// std::cout << "<< D: " << *data << std::endl;
mFace.put(*data);
// string dsha = "id:/localhost/identity/digest-sha256";
// ndn::security::SigningInfo si(dsha);
// // Sign Data packet with default identity
// mKeyChain.sign(*data, si);
// // m_keyChain.sign(*data, signingByIdentity(<identityName>));
// // m_keyChain.sign(*data, signingByKey(<keyName>));
// // m_keyChain.sign(*data, signingByCertificate(<certName>));
// // m_keyChain.sign(*data, signingWithSha256());
// // Return Data packet to the requester
//// std::cout << "<< D: " << *data << std::endl;
// mFace.put(*data);
}
void MNetIO::onRegisterFailed(const Name& prefix, const std::string& reason) {
std::cerr << "ERROR: Failed to register prefix \""
+2 -1
View File
@@ -18,7 +18,8 @@ class MNetIO
public:
MNetIO ();
~MNetIO ();
int sendInterest(char *buf, int size, char* name) ;
int sendInterest(char* name) ;
int sendData(char *buf, int size, char* name) ;
int start(char *prefix) ;
private:
+93 -24
View File
@@ -19,35 +19,87 @@ import (
"github.com/urfave/cli/v2"
"ip-tunnel/iptun"
"ip-tunnel/iptun/ndn"
"minlib/common"
"log"
"os"
"strconv"
"sync/atomic"
"time"
"unsafe"
)
var ipTun iptun.IPTun
var adapter ndn.NDNTunnelAdapter
var ipTunnelConfig *iptun.IPTunnelConfig
// 一个队列,缓存TUN网卡收到的包
var pktChan chan *iptun.IPPacket = make(chan *iptun.IPPacket, 10)
var unSatisfiedInterestCount int64 = 0
//export GoOnData
func GoOnData(cstr *C.char, size C.int) {
//fmt.Println("GoOnData")
// 收到 UPPkt
if size > 0 {
data := C.GoBytes(unsafe.Pointer(cstr), size)
adapter.OnReceivePktFromNDN(&iptun.IPPacket{
Src: waterutil.IPv4Source(data),
Dst: waterutil.IPv4Destination(data),
RawPackets: data,
})
}
sendInterest(ipTunnelConfig.TargetIdentifier)
//atomic.AddInt64(&unSatisfiedInterestCount, -1)
}
//export GoOnInterest
func GoOnInterest(cstr *C.char, size C.int) {
// 接收到兴趣包,提取出其中携带的 IP 并传递给 adapter
data := C.GoBytes(unsafe.Pointer(cstr), size)
adapter.OnReceivePktFromNDN(&iptun.IPPacket{
Src: waterutil.IPv4Source(data),
Dst: waterutil.IPv4Destination(data),
RawPackets: data,
})
func GoOnInterest(cstr *C.char) {
name := C.GoString(cstr)
//common.LogWarn("onInterest: ", name)
// 接收到兴趣包,从缓存中取出一个IP包,封装到一个Data中发出
if len(pktChan) > 0 {
ipPacket := <-pktChan
sendData(ipPacket.RawPackets, name)
} else {
//time.Sleep(10 * time.Millisecond)
sendData(nil, name)
}
}
//export GoOnNack
func GoOnNack() {
//atomic.AddInt64(&unSatisfiedInterestCount, -1)
sendInterest(ipTunnelConfig.TargetIdentifier)
}
//export GoOnTimeout
func GoOnTimeout() {
//atomic.AddInt64(&unSatisfiedInterestCount, -1)
sendInterest(ipTunnelConfig.TargetIdentifier)
}
////int sendInterest(char *buf, int size, char *name) ;
//func sendPacket(pkt []byte, name string) error {
// cstr := C.CString(name)
// C.sendInterest((*C.char)(unsafe.Pointer(&pkt[0])), C.int(len(pkt)), cstr)
// C.free(unsafe.Pointer(cstr))
// return nil
//}
//int sendInterest(char *buf, int size, char *name) ;
func sendPacket(pkt []byte, name string) error {
func sendInterest(name string) error {
cstr := C.CString(name)
C.sendInterest((*C.char)(unsafe.Pointer(&pkt[0])), C.int(len(pkt)), cstr)
C.sendInterest(cstr)
C.free(unsafe.Pointer(cstr))
return nil
}
//int sendData(char *buf, int size, char *name) ;
func sendData(pkt []byte, name string) error {
cstr := C.CString(name)
if pkt == nil {
C.sendData((*C.char)(unsafe.Pointer(nil)), C.int(0), cstr)
} else {
C.sendData((*C.char)(unsafe.Pointer(&pkt[0])), C.int(len(pkt)), cstr)
}
C.free(unsafe.Pointer(cstr))
return nil
}
@@ -57,7 +109,8 @@ func sendPacket(pkt []byte, name string) error {
// @Description:
// @param ipTunnelConfig
//
func StartIPTunnel(ipTunnelConfig *iptun.IPTunnelConfig) error {
func StartIPTunnel(config *iptun.IPTunnelConfig) error {
ipTunnelConfig = config
if err := ipTun.Init(iptun.Config{
InterfaceName: ipTunnelConfig.TunConfig.InterfaceName,
IPv4Addr: ipTunnelConfig.TunConfig.IPv4Addr,
@@ -69,14 +122,30 @@ func StartIPTunnel(ipTunnelConfig *iptun.IPTunnelConfig) error {
}
adapter.Init()
// 在单独的协程里面处理从TUN读取IP包,构造一个Interest并发出
// 在单独的协程里面处理从TUN读取IP包,构造一个Data并发出
go func() {
count := 0
//count := 0
for {
// 从 TUN 中读取IP包,并通过CPacket发出
// 从 TUN 中读取IP包,并通过UPPkt发出
ipPacket := adapter.GetPktFromTun()
sendPacket(ipPacket.RawPackets, ipTunnelConfig.TargetIdentifier+"/"+strconv.Itoa(count))
count++
pktChan <- ipPacket
//sendPacket(ipPacket.RawPackets, ipTunnelConfig.TargetIdentifier+"/"+strconv.Itoa(count))
//count++
}
}()
// 在单独的协程里面不停的发送 Interest,保持已发出未满足的兴趣包数量在30个左右
go func() {
time.Sleep(5 * time.Second)
for {
if atomic.LoadInt64(&unSatisfiedInterestCount) < 30 {
sendInterest(ipTunnelConfig.TargetIdentifier)
atomic.AddInt64(&unSatisfiedInterestCount, 1)
} else {
break
// 睡1ms
time.Sleep(time.Millisecond)
}
}
}()
@@ -86,7 +155,7 @@ func StartIPTunnel(ipTunnelConfig *iptun.IPTunnelConfig) error {
ret := C.start(cstr, C.int(len(ipTunnelConfig.MirConfig.ListenIdentifier)))
C.free(unsafe.Pointer(cstr))
if ret < 0 {
common.LogFatal("start face fail")
log.Fatal("start face fail")
}
}()
// 启动IP隧道程序
@@ -113,14 +182,14 @@ func main() {
mirApp.Action = func(context *cli.Context) error {
ipTunnelConfig, err := iptun.ParseConfig(configFilePath)
if err != nil {
common.LogFatal(err)
log.Fatal(err)
}
// 初始化日志模块
var loggerParameters common.LoggerParameters
loggerParameters.LogLevel = ipTunnelConfig.LogConfig.LogLevel
loggerParameters.ReportCaller = true
common.InitLogger(&loggerParameters)
//var loggerParameters common.LoggerParameters
//loggerParameters.LogLevel = ipTunnelConfig.LogConfig.LogLevel
//loggerParameters.ReportCaller = true
//common.InitLogger(&loggerParameters)
return StartIPTunnel(ipTunnelConfig)
}