|
Q: What if data is lost? What is bits are reversed? What if the
data is received, but the ACK get's lost. What if a dog eats 3 of
every 8 bits? What if ... ?
A: In general you can't deal with every contingency unless your
code is part of the operating system (and can operate asynchronously).
Don't complicate the assignment! Make sure that your code works as
long as everything else works! This is supposed to be a simple project
that does not involve any system programming (no timers, signals,
interrupts, multiplexed I/O, etc.) that simply makes sure you have
some understanding of layered systems.
|
|
Q: When I implement L2_write(),I add sequencer to the data and
write it. Before sending next data, I call L1_read() to read charactor
ack. If the ack is not I need, then I 'll resend the data. I think I
can't read many times before resending because I have only sent one
byte, so receiver can only send one ack, so I can only read one byte
before sending another data, If I read many times before sending
another byte, the process will block when I read second time because
there is nothing to be read. Am I right? and if the ack is lost or the
byte I have send is lost, then there will be nothing to read, so when
I call L1_read to read ack, the process will block. How to deal this
case? could you give me any hint?
A: Your layer2 protocol is more than requested - you can simplify things
by not resending, just return an error if you get an ACK that is not
what you expect. If you really do resend - I don't know how (using
the scheme you describe), the reader would know what is resent data
and what is not. The purpose of the project is not to create a
bullet-proof reliable service at layer 2, but just to make sure you
understand what a layered system is.
|
|
Q: Seems to me like there's an error in the testprog.c code; a
"parent" variable is referred to but once with the line "parent=1" but the
variable is not reference elsewhere.
A: Yup, it shouldn't be there (it was some debugging code I
forgot to remove). testprog.c is now fixed.
|
Q: in l1_read(int cid, char * buff) Is
buff just a char or is it a string of bits when this function
returns?
A: It is a single char (byte), not a string of bits. You have
to build this value from the 8 bits you (I'm assuming here) read using
l0_read(). In C you can do this with bitwise operators |, &,
<<, and >> . For example, to set the nth bit (rightmost bit is
bit 0) in a char named x to be the value 1 you can do this:
x |= 0x01 << n;
This takes the pattern 00000001, shifts it left n times, and ORs the
result with x (and saves the result of the OR in x). Similarly you can
extract the value of the nth bit with something like this:
bitval = x & (0x01 << n);
Caution: you need to be a little careful about how you do things, the
shift operators depend on whether a value is signed or not. See any
C reference for details.
|
|
Q: How do I submit my project?
A: The answer is here.
|
|
Q: Is there test code available?
A: Yup - it's all here
|
Q: In the project description you show l3_write with the
following prototype:
int l3_write(int cid, char c);
In your testprog.c you have:
l3_write(cid,"NetProg99 Rules!!!")
Which is right?
A: There was a typo in the project description, the prototype
for l3_write should be this:
int l3_write(int cid, char *s);
l3_write() should write a null terminated string
(starting at the address passed in as the second parameter).
|
|