Parameters for the various minimsg functions

Why does miniport_remote_create take in an id when there is already an id in the addr parameter? What is the role of the various parameters in miniport_send and miniport_receive functions?
The id in the addr parameter is the actual physical port id that is going to be used for communication by network.c while the id that is passed in as a parameter is the miniport id for the port on the remote machine for which you are creating a remote port. In

int minimsg_send(miniport_t local, miniport_t remote, minimsg_t msg, int len);

local is the local port from which the message is to be sent, remote is the port (remote or local) to which the message is to be sent, msg is the message to be sent and len is the size of the msg buffer. The int returned is either 0 for success or -1 for failure. In

int minimsg_receive(miniport_t local, miniport_t* remote, minimsg_t msg, int *len);

local is the local port on which the message is to be received, remote is a pointer to a remote port from which the message was sent (and therefore can be responded to on), msg is the buffer into which the message has to be received and len is the size of the msg buffer. You can use one of two protocols in order to inform the user about the number of bytes received. Either update len to indicate this or return this number. If you are going to return the received length through len then you can use the return value to indicate any possible error conditions.

Port information

Local ports and remote ports need to contain different kinds of information and yet they are both supposed to have type struct miniport *. How do we do this?

To get started you can declare struct miniport to have all the kinds of information that either local or remote ports need to contain. If there are pieces of information that are valid for local ports but not for remote ports and vice versa then in creating an instance of the corresponding ports these variables can be set to NULL or dummy values. You can then either use this aspect to find the "type" of the port or explicitly keep a variable that indicates if the struct you are looking at is a remote or local port. For example, struct miniport might look like this

        struct miniport { 
                int islocal;
                // local port stuff goes here
                ...
                // remote port stuff goes here
        };
Your code then needs to check the type of the port and behave appropriately. Of course, items common to both local and remote ports should be shared, not duplicated, in the structure.

Header information

Why should I include the sender's network address in the header of each message if I can take this information from the parameter given to the network handler ?.

Your implementation of unreliable communication will be used throughout the entire semester. In the Project 5 you will need to implement an Ad-hoc networking in which a packet should pass through a chain of computers. To apply Ad-hoc routing policies you will need the address of the source of the packet.

miniport_remote_create() and "remote" ports

We need to implement miniport_remote_create function. When must applications use this function ?.

When application A sends a remote message to application B, minimsg_send needs to know the port on which B listens (B's local port). That's why application A creates a remote port that is bound to the B's local port (see network[5-6] examples). The minimsg_receive creates the remote port bound to the sender, not the application that uses the function. You may use miniport_remote_create function inside minimsg_receive function and store in the "remote" parameter the structure assigned to the remote port.