联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2019-05-21 08:46

Part C (50 marks)

In this part of the assignment you will be required to implement the network layer for a host running on a virtual

IP network. You should be familiar with the typical TCP/IP stack (A.K.A. the DoD model or internet protocol

suite), where Ethernet is used as a link-layer protocol and IPv4 used as a network layer protocol. The protocols we

will be using will be virtual - that is, network layer addresses won’t actually correspond to physical interfaces. To

do this, the network stack will be redefined to that shown in the table below.

TCP/IP Stack Protocols Virtual Stack

Network Layer

Transport layer UDP

Network layer IPv4 Link layer

Link Layer Ethernet

As described in the above figure, UDP will be used as your virtual network’s link layer, and you will be required

to implement a virtualisation of IPv4 ontop of this UDP-based link layer. Each UDP socket will correspond to a

link layer interface, and localhost UDP port numbers will be used as the link layer addressing system of this virtual

network.

By the end of this assignment, your implemented host program should be able to:

Accept simple user commands through a basic command line interface (CLI)

Send and receive messages across this virtual network layer

Handle fragmentation of virtual IP packets

Program Invocation

Your program should be able to be invoked from a UNIX or UNIX-like command line as follows. It is expected

that any Python programs can run with version 3.6, and any Java programs can run with version 8. The ip-addr

and ll-addr parameters correspond to the IPv4 address in CIDR notation (indicating the client’s subnet) and link

layer address (UDP port number) of your host program respectively.

Python

python3 assign3.py ip-addr ll-addr

C/C++ make./assign2 ip-addr ll-addr Java

make java Assign2 ip-addr ll-addr

4

Your Task

Command Line Interface (5 marks)

To start with, you should implement a basic command line interface that will allow the user to supply basic

information about the network. Your CLI should prompt users with a single > character, followed by a space.

For the rest of the assignment we define anything wrapped in square brackets as a parameter or field that needs

replacing (NOT as an optional parameter). The CLI should persistently prompt the user for another command until

the program is terminated. For full marks in this section your CLI needs to accommodate the following commands:

gw set [ip-addr] : set the gateway IP address of the LAN the client is a part of to [ip-addr] (overriding

any existing gateway address)

gw get : print the currently stored gateway IP address to stdout, or None if no gateway address has been

specified

arp set [ip-addr] [ll-addr] : insert a mapping from [ip-addr] to [ll-addr] in the host’s ARP table

(overriding any existing entries for [ip-addr])

arp get [ip-addr] : print the currently stored link layer address mapped to [ip-addr] to stdout, or None

if no mapping exists

exit : terminate the program

Error-handling of user input is optional - you won’t receive any marks for this but you can choose to implement it

provided it doesn’t impact on the rest of the assignment.

Sending Messages (15 marks)

To receive marks in this section, your CLI should be able to handle the following additional command:

msg [ip-addr] "[payload]" : send a virtual IPv4 packet to [ip-addr] with the given payload (which will

be supplied as a string)

Any packets sent should have a meaningful identifier and a protocol number of 0. You may assume the that all

payloads will be less than or equal to the MTU of the network’s links, but the DF flag should still be set to 0. Your

program should support any IP address, regardless of whether it is a part of your subnet or not. If your program

needs to send a packet to the gateway address and no gateway address has been specified has been specified, your

program should print No gateway found to stdout. If no required address mapping can be found in the host’s

ARP table, your program should print No ARP entry found to stdout.

Receiving Messages (15 marks)

In addition to sending packets, your program should be able to receive them from other hosts. When your program

receives an IPv4 packet with the protocol indicator set to 0, it should print the payload of that packet to stdout, in

the below format ([ip-addr] should be replaced with the sender’s IPv4 address and [message] should be replaced

with the string encoding of the payload):

Message received from [ip-addr]: "[message]"

When your program receives an IPv4 packet with a non-zero protocol number, it should print the following message

to stdout ([proto-num] should be the hexadecimal representation of the protocol formatted as 0x??):

Message received from [ip-addr] with protocol [proto-num]

You can assume all packets sent to your program are valid IPv4 packets. You should be able to receive messages

at any time without blocking the CLI, and any messages should be printed cleanly (without any CLI prompts or

responses disrupting the message contents). Remember to backspace the current prompt (the > character) before

printing the output.

5

IP Fragmentation (15 marks)

To receive marks in this section your program should be able to handle IP fragmentation. Your CLI should support

the following extra commands:

mtu set [value] : set the MTU of the network’s links as the specified [value]

mtu get : print the currently stored MTU (the default MTU should be 1500)

Virtual packets that are longer than the specified MTU (or the default MTU if none has been specified) should be

fragmented before transmission. The length of a virtual packet is equal to the length of the IPv4 header added to

the length of the IPv4 payload (i.e. you don’t need to consider the length of the non-virtual headers). You can

assume the value of the MTU will never be smaller than 100.

Your program should also be able to receive packets that have been fragmented (and display them as a single

message).

Example CLI output

python3 assign2.py 192.168.1.1/24 1024

> gw get

None

> gw set 192.168.1.30

> gw get

192.168.1.30

> msg 192.168.1.2 "hello"

No ARP entry found

> arp get 192.168.1.2

None

> arp set 192.168.1.2 2222

> arp get 192.168.1.2

2222

> msg 192.168.1.2 "hello"

> mtu get

1500

> mtu set 1600

> mtu get

1600

Message received from 192.168.1.2: "hello there, thankyou for your message"

Message received from 192.168.1.3 with protocol 0x06

> exit

Packet Formatting

Your IPv4 packets don’t need to contain meaningful values for the DCSP/ECN fields, nor are you required to

compute a correct checksum. You can assume packets will never contain any options and subsequently that the

IHL will always be 5. The TTL field should contain some meaningful value (i.e. to allow the packet to reach its

destination).

6


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp