i. The ordering of these ids
is not significant, i.e. a link is defined by only its endpoints
{i, idi,j}.
It may be assumed that there are no duplicates in
idi,0 .. idi,ni-1, and
i ≠ idi,j.
The network will be specified in a text file containing p
on the first line and the respective lines of the node table on the next
p lines. For example, 4 nodes connected in a square would be
specified as:
4
2 3 1
2 0 2
2 3 1
2 0 2
Note that the order of node ids across each line is not significant.
Time across the network progresses in units of a jiffy.
There will be one jiffy of delay between when a node receives a packet and
when it sends it. There is also one jiffy of delay between the
sending of packets on the source node of a message.
A network schedule of is a list of messages with items
in the following format:
| time |
srcAddr |
destAddr |
msgLen
|
where time is in units of jiffys and is the (local) time when
node srcAddr sends the first packet of a message of
length msgLen to node
destAddr (if this time has already passed, the message should sent as
soon as posible).
The special entry:
will cause termination of all processes at (or as soon as possible
after) local time t It may be assumed that time is
non-decreasing as we traverse down the list, that srcAddr ≠
destAddr, there is at most 1 message per srcAddr
per timestep and msgLen ≤ 4.
Example network specification files and schedules will be made available on
partch:/dept/dcs/comp2310/public/ass2; the utility program
genNetConf in the CS Linux student system can be used to generate
network specification files from common network topologies (i.e. ring, tree,
star, mesh); type the command genNetConf for how to use it.
Requirements
If you submit netSim.c, it must launch the simulation, i.e.
when compiled, it must have the following synopsis:
If you submit only NetSim.java, it must launch the
simulation with the synopsis:
java -ea NetSim netFile schedFile
Here netFile is the name of a text file containing a network
specification, and schedFile is the name of a text file
containing a network schedule. Launching the simulation must involve
creating a group of p processes (possibly including the
initial process) which each simulates one node of the network. Each
process must initiate messages according to the schedule in
schedFile, and forward any packets it receives to an appropriate node.
Sockets are recommended for the passing of packets, although any form of
IPC may be used.
All messages must be (eventually) delivered; indeed, it is desirable
they get delivered along a path of shortest distance.
Please note the following for your program:
- it may assume that netFile and schedFile are in
the correct format and that netFile has been generated by
genNetConf.
- it use the netAux library
(or netAux class, which has methods of exactly the same names
and signatures) to get the value of the network jiffy, and to log the
sending and receiving of messages and packets. Your code should
produce no other output.
- They will be tested on a 4-core Linux machine like those
in the CS student labs, so make sure it works on these machines!
- They should be written with good programming style (C
code should not produce any warnings when compiled with
the -Wall option!). They should be well commented and
formatted to a standard width of 80 characters, so as to enable the
reader (this includes your tutor/marker!) to both easily read it and
understand how it works. Identifiers should be meaningful and (unless
their role is trivial) commented where declared, any constants should
be named rather than hard-coded, and defensive programming should be
used. The latter includes checks being made for system calls that can
fail due to resource limitations (anyting that creates a file descriptor or process); once detected, a message should be
generated with a call to the system error function perror()
and the process should exit with a status of 2. It also includes using
assert to perform other kinds of checks (including overflow
of any fixed-length data structures that you use).
All file descriptors should be closed before the process exits.
- All submitted files must have a preamble making a declaration
about the work you have submitted. The provided template files
(netSim.c, NetSim.java) come with
such a preamble. You must add your name and student number where
indicated. If you need to modify the declaration, e.g. you did in fact
receive substantial assistance from another person who is not course staff,
you should modify the text to say so. Code obtained from the internet
will receive no marks even if acknowledged.
The solution on the problem on all the given network topologies is
non-trivial. You can simplify the problem by restricting msgLen = 1,
and use restricted topologies (e.g. a ring and star) and still gain
60% of marks
Compilation and Running Codes On and Off-site, Java API
On the CS student system, the commands
gcc -Wall -I $COMP2310/include -o netSim netSim.c $COMP2310/lib/netAux.o
javac NetSim.java
should be sufficient to compile the respective programs. To run
offsite, download
the netAux.h, netAux.c
and/or NetAux.java sources to your working directory.
The commands to compile the C program is now:
gcc -Wall -o netSim netSim.c NetAux.c
The standard Java classes
ProcessBuilder (a combined fork/exec),
Socket, and
Selector
may be useful for this assignment.
There are tutorials for Java
sockets
and select too.