NS - Simulation Experiment - FTP

xiaoxiao2021-03-06  40

FTP experiment summary

1.FTP client

a. ftp configuration file format (refer to the init file)

IP address of the host to log in

username

password

The path name of the file to get (absolutely followed)

Files in the current FTP directory

b. log file format (refer to last.log file)

Total number of bytes received

Time used

Transmission rate (bytes / second)

Function Description

The SYSTEMS structure is declared in / *ftp_var.h, encapsulates the configuration file structure *

Typedef struct {

Char * ipadd;

Char * user;

Char * pwd;

Char * filename; // Enter the file name

Char * outfilename; // Output file name

} Systems;

EXTERN Systems * sysptr;

Sys_next function is defined in /*main.c * /

Long Sys_Next (Systems * Sysptr)

Read the configuration information from the file from the file to the Sysptr global variable according to the blank character.

CMDSCANNNERHELPER function is defined in /*main.c * /

Void cmdscannerhelper ()

According to the setting information of the configuration file, form an FTP command, send it to the server.

CMDSBYE functions are defined in / *Main.c * /

Void cmdsbye ()

Send the FTP command BYE to the server, end the transfer.

Automated landing in the login function in / *ftp.c * /

INT login (char * host)

According to the setting information of the configuration file, form an FTP command, send it to the server.

Such as:

STRCPY (user, sysptr-> user);

STRCPY (Pass, Sysptr-> PWD);

n = Command ("User% S", User;

IF (n == continue) {

n = Command ("Pass% S", PASS);

}

IF (n == continue) {

AFLAG ;

Acct = getPass ("Account:");

n = Command ("ACCT% S", ACCT);

}

d. ftp client, according to the setting of the init file, to the server download file to the current directory. The front of the file name is taken with P head, plus the process number, plus the file name set in the init file. (Such as Process27310-1.tar.gz)

e. Note that the IP destination address is set to the virtual address corresponding to the real address of the server in the init file.

2. Configuration of the emulator

a. Work script of the emulator

SET NS [New Simulator]

$ NS Use-Scheduler Realtime

Set n1 [$ ns node]

Set N2 [$ ns node]

Set N3 [$ ns node]

$ NS MAP 10.88.88.81 10.88.88.99 $ N2

$ NS MAP 10.88.88.81 10.88.88.99 $ N3

$ NS MAP 10.88.88.74 21 10.88.88.98 $ n1

$ NS DUPLEX-LINK $ N2 $ N1 10MB 10MS DROPTAIL

$ NS DUPLEX-LINK $ N3 $ N1 10MB 10MS DROPTAIL

Set myfilter [new intend]; # create the bpf

Set dev [$ myfilter open ready eth0]

$ MyFilter Filter "DST Host 10.88.88.98" SET IPNET2 [New Agent / Outthread]; # create a network agent

$ ipnet2 Open Writeonly

$ NS Attach-Agent $ N2 $ ipnet2; # attach agent to the node.

$ n2 attach $ ipnet2 8000

SET IPNET3 [New Agent / Outthread]; # Create a network agent

$ ipnet3 open writeonly

$ NS Attach-Agent $ N3 $ ipnet3; # attach agent to the node.

$ n2 attach $ ipnet3 8000

Set ipnet1 [new agent / outthread]; # Create a network agent

$ ipnet1 open writeonly

$ NS Attach-Agent $ N1 $ ipnet1; # attach agent to the node.

$ n1 attach $ ipnet1 8000

$ ns at 432000.0 "finish"

Proc finish {} {

EXIT 0

}

$ NS RUN

b. Add

The host where the FTP client is located, the route Route Add -Host 10.88.88.98 GW 10.88.88.86

Hosts in FTP Server Add Route Route Add -Host 10.88.88.99 GW 10.88.88.86

c. Simulation in the real network topology environment in the emulator

FTP client real IP 10.88.88.81 virtual IP 10.88.88.99

Other clients ... (current experiment only support two clients, two clients can be on the same host, can also be on different hosts)

FTP Server real IP 10.88.88.81 virtual IP 10.88.88.98

NS emulator real IP 10.88.88.86

3. Modification of the FTP protocol in the emulator

a. Modify the FTP application layer data

// Process the application layer because there is a practical data

Char * app_header = (char *) TCPHEADER;

App_Header = TCPHEADER-> DOFF * 4;

Char * ptr = app_header;

Char buff [255] = {0}, Tempbuf [255] = {0};

CHAR * Servip = (char *) BUFF;

STRNCPY (BUFF, PTR, 4);

IF (! Strcmp (BUFF, "Port"))

{

STRNCPY (BUFF, PTR 5, 91-71);

For (INT II = 0; II <4;)

{

IF (* servip) == ',')

{

II ;

* servip = '.';

}

IF (ii == 4)

Break;

Servip ;

}

* servip = 0;

servip = buff;

STRNCPY (Tempbuf, PTR Strlen (BUFF) 5,91-71-Strlen (BUFF));

// Printf ("Tempbuf IS% S / N", TEMPBUF);

INT count = 0;

For (int JJ ​​= 0; true; jj ) {

IF (Tempbuf [JJ] == 13)

{

Count = jj;

Break;

}

}

// htable __-> printall ();

TMPBUCKET = HTABLE __-> lookupr_ip (servip); // Get server address

INT DIFF = Strlen (TmpBucket-> Virhost_IP) - Strlen (Servip);

STRCPY (BUFF, TMPBUCKET-> VIRHOST_IP);

// Printf ("BUF IS% S / N", BUFF);

Servip = (char *) BUFF;

For (INT II = 0; * servip;)

{

IF ((* servip) == '.')

{

II ;

* servip = ',';

}

Servip ;

}

// Direct copy memory to the area you want

Memmove (PTR 5, BUFF, STRLEN (BUFF));

Memmove (PTR 5 Strlen (BUFF), TEMPBUF, COUNT

PTR [5 Strlen (BUFF) count] = 13;

PTR [5 Strlen (BUFF) Count 1] = 10;

CH-> size () = cc diff; // modify the length, and the leaf package length

Ipheader-> ip_len = ipheader-> ip_len diff;

}

b. Amendment to the protocol

IF (ipheader-> ip_p == 6 && ntohs (tcpheader-> dest) == 21) {}

Else IF (ipheader-> ip_p == 6 && (ntohs (tcpheader-> dest) == 20)) {}

Else IF (ipheader-> ip_p == 6 && ntohs (tcpheader-> source) == 21) {}

Else IF (ipheader-> ip_p == 6 && ntohs (tcpheader-> Source) == 20) {}

It is mainly seen by the above four judges to see the direction of an IP packet.

Destination Port 21 ----> Control Port to Server

In this case, we have to insert the ports in the Hash table into the hash table.

And modify the corresponding application layer data like A

Destination Port 20 ---> Data Port to Server

Source port 21 ---> Control packets returned from the server

Original port 20 ----> Packets returned from the server

Other circumstances we just have to find true IP and virtual IP in the Hash table.

转载请注明原文地址:https://www.9cbs.com/read-78178.html

New Post(0)